Setting Up PlantUML for Obsidian and Hugo
Setting Up PlantUML for Obsidian and Hugo
Section titled “Setting Up PlantUML for Obsidian and Hugo”Create beautiful, maintainable diagrams that render perfectly in both your Obsidian vault and your Hugo static site. This guide shows you how to configure PlantUML so your diagrams work everywhere.
Table of Contents
Section titled “Table of Contents”- What You’ll Build
- What is PlantUML?
- Prerequisites
- Part 1: Obsidian Setup
- Part 2: Hugo Setup
- Testing Your Setup
- Creating Your First Diagram
- Common Diagram Types
- Troubleshooting
- Next Steps
What You’ll Build
Section titled “What You’ll Build”A unified PlantUML workflow that:
- Renders diagrams in Obsidian preview mode
- Exports cleanly to Hugo without modifications
- Uses the same syntax in both environments
- No local PlantUML installation required
- Automatic server-side rendering
The workflow:
Why use PlantUML?
- Text-based diagrams (version controllable)
- No external diagram tools needed
- Consistent rendering across platforms
- Easy to update and maintain
- Professional-looking results
Time to complete: 15-20 minutes
What is PlantUML?
Section titled “What is PlantUML?”PlantUML is a tool that lets you create diagrams from plain text descriptions.
Example
Section titled “Example”Instead of drawing a flowchart in a GUI tool, you write:
And PlantUML renders it as a sequence diagram.
How It Works
Section titled “How It Works”- You write: PlantUML syntax in a markdown code block
- PlantUML server: Converts text to diagram image (SVG/PNG)
- You see: Beautiful diagram in your preview/website
Supported Diagram Types
Section titled “Supported Diagram Types”- Sequence diagrams - Show interactions between components
- Flowcharts/Activity diagrams - Show workflows and processes
- Class diagrams - Show object relationships
- State diagrams - Show state transitions
- Component diagrams - Show architecture
- Deployment diagrams - Show infrastructure
- Timing diagrams - Show time-based interactions
- And many more!
Prerequisites
Section titled “Prerequisites”Before starting, verify you have:
Required
Section titled “Required”- Obsidian installed and working
- Check: You can open your vault
- Hugo site set up and working
- Check:
hugo versionshows v0.120.0 or higher - Your site should build successfully with
hugo
- Check:
Recommended
Section titled “Recommended”- Basic markdown knowledge
- Familiarity with your Hugo theme
- Text editor for editing Hugo layout files
No Installation Required
Section titled “No Installation Required”You do NOT need:
- Java installed
- PlantUML JAR file
- Local PlantUML installation
- Graphviz
We use the PlantUML.com rendering service which handles all processing server-side.
Part 1: Obsidian Setup
Section titled “Part 1: Obsidian Setup”Configure Obsidian to render PlantUML diagrams in preview mode.
Step 1: Install PlantUML Community Plugin
Section titled “Step 1: Install PlantUML Community Plugin”- Open Obsidian Settings (Cmd+, or Ctrl+,)
- Navigate to Community plugins
- If disabled, click “Turn on community plugins”
- Click “Browse” button
- Search for: “PlantUML”
- Find “PlantUML” by joethei
- Click “Install”
- Click “Enable”
What you should see: PlantUML now appears in your installed plugins list with a checkmark.
Step 2: Configure PlantUML Plugin
Section titled “Step 2: Configure PlantUML Plugin”The default settings work great, but let’s verify them:
-
Obsidian Settings → Community plugins
-
Under PlantUML, click the gear icon
-
Verify these settings:
Renderer:
PlantUML Server- This uses plantuml.com for rendering (no local installation)
Server URL:
https://www.plantuml.com/plantuml- Official PlantUML rendering service
Output format:
svg- SVG gives best quality at any zoom level
-
Save and close settings
Security note: Diagrams are sent to plantuml.com for rendering. Don’t include sensitive information in diagrams if this is a concern. For private diagrams, you can self-host a PlantUML server (advanced, not covered here).
Step 3: Test in Obsidian
Section titled “Step 3: Test in Obsidian”Create a test note to verify the plugin works:
-
Create a new note in your vault:
plantuml-test.md -
Paste this content:
# PlantUML TestThis is a simple sequence diagram:```plantuml@startumlAlice -> Bob: HelloBob -> Alice: Hi!@enduml``` -
Switch to Preview mode (Cmd+E or Ctrl+E)
Expected result: You should see a rendered sequence diagram showing Alice and Bob exchanging messages.
If you see a rendered diagram: Success! Obsidian is working. Move to Part 2.
If you see raw code: Check troubleshooting section below.
Part 2: Hugo Setup
Section titled “Part 2: Hugo Setup”Configure Hugo to render PlantUML code blocks automatically.
Step 1: Create Render Hook Directory
Section titled “Step 1: Create Render Hook Directory”Hugo uses “render hooks” to customize how markdown elements are rendered.
# Create directory for markdown render hooksmkdir -p ~/Developer/mementropy/layouts/_default/_markupWhat this does: Creates the directory where Hugo looks for custom markdown renderers.
Step 2: Create PlantUML Render Hook
Section titled “Step 2: Create PlantUML Render Hook”Create a file that tells Hugo how to render plantuml code blocks:
# Create the render hook filetouch ~/Developer/mementropy/layouts/_default/_markup/render-codeblock-plantuml.htmlNow edit this file with the following content:
File: layouts/_default/_markup/render-codeblock-plantuml.html
{{- $uml := .Inner | replaceRE "^\n" "" | replaceRE "\n$" "" -}}{{- $encoded := $uml | base64Encode -}}{{- $encodedURL := $encoded | replaceRE "\\+" "-" | replaceRE "/" "_" | replaceRE "=" "" -}}<div class="plantuml"> <img src="https://www.plantuml.com/plantuml/svg/{{ $encodedURL }}" alt="PlantUML Diagram" loading="lazy" /></div>What this does:
- Takes the PlantUML code from the code block (
.Inner) - Base64 encodes it
- Makes it URL-safe (replace +, /, remove =)
- Generates an image URL pointing to plantuml.com
- Renders as an
<img>tag with lazy loading
Step 3: Configure Hugo Markup Settings
Section titled “Step 3: Configure Hugo Markup Settings”Hugo needs permission to render raw HTML (for the render hook):
Edit: hugo.toml (or config.toml)
Add or verify this section:
# Markup configuration[markup] [markup.goldmark] [markup.goldmark.renderer] unsafe = true # Allow raw HTML for shortcodes and render hooksWhat this does: Allows Hugo’s Goldmark renderer to output raw HTML, which is necessary for the PlantUML image tags.
Save the file.
Step 4: Verify Hugo Configuration
Section titled “Step 4: Verify Hugo Configuration”Check that your config is valid:
cd ~/Developer/mementropyhugo configLook for: markup.goldmark.renderer.unsafe = true in the output.
If you see it: Configuration is correct! Move to testing.
If not: Double-check you added the config to the right section.
Testing Your Setup
Section titled “Testing Your Setup”Test that PlantUML works in both Obsidian and Hugo.
Test 1: Obsidian Rendering
Section titled “Test 1: Obsidian Rendering”Goal: Verify diagrams render in Obsidian preview.
-
Open Obsidian
-
Create or edit a markdown file with PlantUML:
```plantuml@startumlstart:Write documentation;:Add diagrams;:Publish!;stop@enduml``` -
Switch to Preview mode (Cmd+E)
Expected Result
Section titled “Expected Result”You should see a flowchart with three steps and start/stop nodes.
Pass: Diagram renders Fail: See troubleshooting below
Test 2: Hugo Local Rendering
Section titled “Test 2: Hugo Local Rendering”Goal: Verify diagrams render when Hugo builds your site.
-
Create a test post in your Hugo site:
Terminal window # Create a test postecho '---title: "PlantUML Test"date: 2025-01-11draft: false---# Testing PlantUML```plantuml@startumlAlice -> Bob: Can you see this?Bob -> Alice: Yes, it works!@enduml```' > ~/Developer/mementropy/content/blog/plantuml-test.md -
Start Hugo server:
Terminal window cd ~/Developer/mementropyhugo server -
Open browser to
http://localhost:1313 -
Navigate to your test post (usually
/blog/plantuml-test/)
Expected Result
Section titled “Expected Result”You should see:
- The heading “Testing PlantUML”
- A rendered sequence diagram showing Alice and Bob
Pass: Diagram renders correctly Fail: See troubleshooting below
Test 3: Obsidian to Hugo Workflow
Section titled “Test 3: Obsidian to Hugo Workflow”Goal: Verify diagrams created in Obsidian export to Hugo correctly.
-
In Obsidian, create a note with a diagram:
---title: "My Workflow"date: 2025-01-11draft: false---# My Publishing Workflow```plantuml@startumlskinparam monochrome truestart:Edit in Obsidian;:Sync to Hugo;:Publish;stop@enduml``` -
Verify it renders in Obsidian (Preview mode)
-
Sync/export to Hugo (using your normal workflow):
- If using obsidian-export: Run your sync script
- If manual: Copy the file to Hugo content directory
-
Check Hugo preview:
Terminal window hugo server -
Visit the page in your browser
Expected Result
Section titled “Expected Result”The diagram should look identical (or very similar) in both Obsidian and Hugo.
Pass: Same diagram in both places Fail: Check file sync and paths
Creating Your First Diagram
Section titled “Creating Your First Diagram”Now that everything is configured, let’s create a useful diagram.
Example: Simple Flowchart
Section titled “Example: Simple Flowchart”Create a note with this content:
---title: "Decision Making Process"draft: false---
# Decision Making Process
```plantuml@startumlskinparam monochrome trueskinparam shadowing falseskinparam defaultFontName Arial
start
:Receive new idea;
if (Is it feasible?) then (yes) :Research thoroughly; if (Still good idea?) then (yes) :Create plan; :Execute; stop else (no) :Document learnings; stop endifelse (no) :Archive for later; stopendif
@enduml```What this creates: A decision tree showing how to evaluate new ideas.
Styling explained:
skinparam monochrome true- Black and white (cleaner)skinparam shadowing false- No shadows (crisper)skinparam defaultFontName Arial- Readable font
Common Diagram Types
Section titled “Common Diagram Types”1. Sequence Diagram (Communication)
Section titled “1. Sequence Diagram (Communication)”Use for: Showing interactions between systems or components
2. Activity Diagram (Workflow)
Section titled “2. Activity Diagram (Workflow)”Use for: Showing step-by-step processes
3. Component Diagram (Architecture)
Section titled “3. Component Diagram (Architecture)”Use for: Showing system architecture
4. State Diagram (State Machine)
Section titled “4. State Diagram (State Machine)”Use for: Showing state transitions
Troubleshooting
Section titled “Troubleshooting”Problem: Diagrams Don’t Render in Obsidian
Section titled “Problem: Diagrams Don’t Render in Obsidian”Symptoms:
- See raw PlantUML code instead of diagram
- Preview mode shows code block
Solutions:
-
Verify plugin is enabled:
- Settings → Community plugins → PlantUML (should have checkmark)
-
Check code block syntax:
- Must be ```plantuml (lowercase)
- Must have @startuml and @enduml tags
-
Test with simple diagram:
-
Check plugin settings:
- Renderer: PlantUML Server
- URL: https://www.plantuml.com/plantuml
-
Reload Obsidian:
- Cmd/Ctrl + R to reload
Problem: Diagrams Don’t Render in Hugo
Section titled “Problem: Diagrams Don’t Render in Hugo”Symptoms:
- See raw PlantUML code on website
- Or see blank/broken image
Solutions:
-
Verify render hook exists:
Terminal window ls ~/Developer/mementropy/layouts/_default/_markup/render-codeblock-plantuml.htmlShould exist and contain the template code.
-
Check hugo.toml configuration:
Terminal window grep -A 3 "\[markup\]" ~/Developer/mementropy/hugo.tomlShould show
unsafe = true -
Rebuild Hugo:
Terminal window cd ~/Developer/mementropyhugo server --disableFastRenderForce full rebuild
-
Check browser console (F12):
- Look for image loading errors
- PlantUML.com might be blocked by firewall
-
Test the image URL directly:
- Right-click broken image → Copy image address
- Paste in new browser tab
- Should show diagram
Problem: Diagrams Look Different in Obsidian vs Hugo
Section titled “Problem: Diagrams Look Different in Obsidian vs Hugo”Symptoms:
- Diagram renders but looks different in each environment
- Colors, fonts, or layout differ
Solutions:
-
Use explicit styling (recommended):
-
Both environments use same server:
- Obsidian plugin: Uses plantuml.com
- Hugo render hook: Uses plantuml.com
- Should be identical if using same skin params
-
Check PlantUML plugin version:
- Update to latest version
- Settings → Community plugins → PlantUML → Update
Problem: Syntax Errors in Diagrams
Section titled “Problem: Syntax Errors in Diagrams”Symptoms:
- Error message in rendered output
- “Syntax error” or similar
Solutions:
-
Use PlantUML syntax checker:
- Visit: https://www.plantuml.com/plantuml/uml/
- Paste your diagram code (without @startuml/@enduml)
- See live errors
-
Common syntax mistakes:
- Missing @startuml or @enduml
- Unclosed quotes:
"forgot to close - Wrong arrow: Use -> not right arrow symbol
- Missing semicolons (some diagram types)
-
Reference documentation:
- PlantUML docs: https://plantuml.com/
- Specific diagram type guides
Best Practices
Section titled “Best Practices”1. Always Use Skin Params
Section titled “1. Always Use Skin Params”Start every diagram with consistent styling:
Why: Ensures diagrams look the same everywhere.
2. Keep Diagrams Simple
Section titled “2. Keep Diagrams Simple”- One diagram = one concept
- Break complex diagrams into multiple simpler ones
- Use notes to explain details
3. Version Control Your Diagrams
Section titled “3. Version Control Your Diagrams”Since PlantUML is text:
- Track changes in git
- See diagram evolution over time
- Easy to review in PRs
4. Use Comments
Section titled “4. Use Comments”5. Test in Both Environments
Section titled “5. Test in Both Environments”Before publishing:
- Renders in Obsidian preview
- Renders in Hugo local server
- Looks good at different zoom levels (SVG benefit)
Quick Reference
Section titled “Quick Reference”Basic Syntax
Section titled “Basic Syntax”| Element | Syntax |
|---|---|
| Start diagram | @startuml |
| End diagram | @enduml |
| Comment | ' comment text |
| Arrow | A -> B |
| Note | note right: text |
| If condition | if (condition) then (yes) |
| Start/stop | start / stop |
Useful Resources
Section titled “Useful Resources”| Resource | URL |
|---|---|
| Official PlantUML docs | https://plantuml.com/ |
| Live editor | https://www.plantuml.com/plantuml/uml/ |
| Real-world examples | https://real-world-plantuml.com/ |
| Obsidian plugin | https://github.com/joethei/obsidian-plantuml |
File Locations
Section titled “File Locations”| Purpose | Path |
|---|---|
| Hugo render hook | layouts/_default/_markup/render-codeblock-plantuml.html |
| Hugo config | hugo.toml (or config.toml) |
| Obsidian plugins | .obsidian/plugins/obsidian-plantuml/ |
Next Steps
Section titled “Next Steps”Now that you have PlantUML working, consider:
- Add diagrams to existing posts - Visualize complex concepts
- Create architecture diagrams - Document your system design
- Diagram workflows - Show how processes work
- Explore advanced PlantUML - Gantt charts, mind maps, JSON/YAML visualization
Related guides:
- Alfred Workflows - Uses PlantUML for workflow diagrams
- Scheduled Publishing - Shows publishing flow diagram
- Remote Publishing - Visualizes remote trigger flow
Summary
Section titled “Summary”What you accomplished:
- Installed Obsidian PlantUML plugin
- Configured Hugo render hook for PlantUML
- Created unified syntax that works in both environments
- Tested with real diagrams
- Ready to create documentation with diagrams
Key benefits:
- Text-based diagrams (version controllable)
- Same syntax everywhere
- No local installation required
- Professional results
- Easy to maintain
Time investment: 15-20 minutes Value: Better documentation forever!
Last updated: 2025-01-11