I often need to embed a simple sequence diagram into a page and I came across swimlanes.io which does exactly what I need. You can define a sequence diagram, download an image or embed a diagram into a page. I like the simplicity of it, however, I sometimes need to make a slight modifications to my sequence diagram, for example, to highlight a specific part of it by changing a color of a line, etc. And I want to write a code of my sequence diagram directly in Hugo’s page without going to swimlanes.io to change it.
To do this, I developed a Hugo shortcode for swimlanes and slightly altered the swimlanes code to be able to embed a diagram using a base64 string. I also modified the diagram style to match my Hugo theme.
The following example shows how I use it in Hugo.
{{< swimlanes >}}
note: Example request-response interaction between a client and a server via a proxy
client -> proxy: request
proxy -> server: forwarded request
server -> proxy: response
proxy -> client: response
{{< /swimlanes >}}
This produces the below diagram.
I do this by modifying the style of the diagram in JavaScript. You can modify any part of it, however, you need to explore the html code of the diagram and find correct element IDs to do so.
document.getElementById('swimlanes_2').onload = ()=>{
var c = $("#swimlanes_2").contents()
c.find('#element_2 polyline').css("stroke","red")
c.find('#element_2 div').css("border-color","red")
c.find(".lane-titles.bottom").css("display", "none")
}