PlantUML is a really awesome way to create diagrams by writing code instead of drawing and dragging visual elements. Markdown is a really nice documentation tool.
Here’s how I combine the two, to create docs with embedded diagrams.
Get the command-line PlantUML from the download page or your relevant package manager.
Use your favorite markdown or text editor. Most (if not all) developer-oriented text editors have some kind of markdown support.
Remember that md files can contain html, and that html is passed-through to the generated html as-is.
When you want to embed a diagram, create a hidden div:
Now start a code block by indenting or typing 3 backticks. The first line of the code block must be
@startuml followed by a file name (with no extension). The following lines should be the actual diagram code, ending with
@enduml. End the code block and close the div.
Finally, to actually show the diagram in the document, add an image in markdown:
The name must be the same name as in the
@startuml command, with a
Regular **Markdown** here.
On the command line:
plantuml -tsvg FILENAME
Where FILENAME is the name of the markdown file.
For every PlantUML block in the file, one svg diagram is generated. When the markdown to html converter is running, the html will contain image links to the generated images.
If for some reason you want to use PNG files for the diagrams and not SVG, use
!(firstDiagram.png) in the image reference and remove the
-tsvg in the command line. PNG files are compatible in more places, but they don’t look good when zooming in and on high resolution displays.
If you host the files in GitHub (or other services that convert md to html on the fly), the last step is uploading or pushing the files. Make sure to include everything: the markdown and the generated diagrams.
Otherwise, use your favorite tool for converting markdown to html - a markdown editor or a command line tool.
If you copy the above markdown code into a file and run plantuml as instructed, the result will be the following: