Open traut opened 10 months ago
This is a low-priority plugin since it depends on external tools and supplements an existing way of using Mermaid diagrams.
I think this plugin is duplicate of content text
. We can use:
content text {
format_as = "code"
code_language = "mermaid"
text = <<-EOT
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
EOT
}
And leave image rendering for markdown viewer. Since this will produce:
'''mermaid
graph TD;
A-->A;
A-->C;
B-->D;
C-->D;
'''
Resulting in viewers that support mermaid code blocks rendering image instead (e.g: Github):
graph TD;
A-->A;
A-->C;
B-->D;
C-->D;
@dobarx indeed, it provides similar functionality, but, as noted in the "Background", it might be beneficial to have a static image generator. See also "Important" block with a couple of notes.
I suggest we leave this issue in draft
state for now, to be revisited in the future
Hmm, then there could be two approaches:
mermaid
extension I see from docs we render differently based on output:
.md
output just with codeblocks.html
output with client-side rendering (JS renders when browser opens).pdf
output with server-side image rendering (requires Chrome or mermaid CLI as dependencies)mermaid
as recommended diagram language and use D2
which is implemented in Go and will render images for all outputs without any external dependencies. Also plugs just as simple goldmark library extension.
Background
Users can add Mermaid diagrams to the documents using
content.text
withformat_as
set tocode
andcode_language
set tomermaid
, but in the case user's Markdown renderer does not support Mermaid diagrams,fabric
should support static rendering.Design
The plugin draws Mermaid diagrams as static images.
Specification
code
-- a required string attribute that contains a Mermaid code.alt_text
-- an optional string attribute with alt text for the image tagoutput_file
-- a required string attribute that contains a path for the output fileBehaviour
The plugin renders mermaid diagram code into a static image and returns a Markdown image tag (similar to
content.image
).The
code
value is treated as Go template string (query_result
object from the local context)For example,
renders image
into
/tmp/diagram.png
and returnsDeliverables
content.mermaid_image
plugin