oxygenxml / dita-ot-diagrams-plugin

Dynamically convert PlantUML content inside DITA topics to SVG
Apache License 2.0
9 stars 3 forks source link

Render Mermaid diagrams locally #7

Closed darrenn-jackson closed 1 year ago

darrenn-jackson commented 1 year ago

author darrenn-jackson darrenn.jackson@gmail.com 1676392110 -0600 committer Darrenn Jackson darrenn.jackson@hpe.com 1676395010 -0600

Local browser rendering for Mermaid diagrams

While using this plugin for one of my docs, I frequently got HTTP 503 error codes during the build process from the Mermaid web service. This will likely happen to anyone else who uses this plugin. These changes cause the browser to download the Mermaid JS library and render the diagram during page load.

Signed-off-by: Darrenn Jackson darrenn.jackson@hpe.com

raducoravu commented 1 year ago

Thanks @darrenn-jackson I added your changes to a separate branch in the repository: https://github.com/oxygenxml/dita-ot-diagrams-plugin/blob/html-output-use-mermaid-js/com.oxygenxml.diagrams.svg/xsl/xhtmlSVG.xsl Maybe I can find some time to work on it if others are interested in it. Two problems I see with your changes:

I will close the PR.

darrenn-jackson commented 1 year ago

@raducoravu I agree that those are problems with the changes. The Mermaid JS file should only be pulled in once as you say, but I think that the JS file <script> tag must appear before the first embedded Mermaid diagram description.

I changed the <span> in your original plugin with a <div> because I thought I had to in order to implement theming to match my company's color scheme (using an init directive). I just now tried to find the docs page that made me think that, but can't find one. So reverting back to a <span> probably makes sense.

raducoravu commented 1 year ago

@darrenn-jackson you probably found the sample here and worked from it: https://mermaid.js.org/config/usage.html#simple-full-example Indeed as they suggest using a "pre" element, you cannot surround a pre with a span, so they seem to recommend using a div like you did. About the script reference, notice that it's at the very end of the HTML document. Probably that "startOnLoad: true" parameter passed to it means that once the entire HTML document is loaded, it should locate all the "pre" elements and replace them with images. So it does not really matter where it's referenced.