goldmark-plantuml is an extension for goldmark.
You can plantuml to build svg image in your markdown like mume
goldmark.New(
goldmark.WithExtensions(
extension.GFM,
uml.Default,
),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(),
)
If you are using other fenced codeblock extensions(such as yuin/goldmark-highlighting), new extensions will override the old one.
You can use OhYee/goldmark-fenced_codeblock_extension to fix it.
Just init goldmark like this
(50
is LRU cache size)
goldmark.New(
goldmark.WithExtensions(
extension.GFM,
ext.NewExt(
uml.RenderMap(50, "plantuml-svg"),
ext.RenderMap{
Languages: []string{"*"},
RenderFunction: ext.GetFencedCodeBlockRendererFunc(highlighting.NewHTMLRenderer()),
},
),
),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(),
)
If you have more than two fenced codeblock extensions, you can register them like this
ext.NewExt(
ext.RenderMap{
Languages: []string{"mermaid"},
RenderFunction: mermaid.NewMermaid(50, "mermaid").Renderer,
},
ext.RenderMap{
Languages: []string{"dot-svg"},
RenderFunction: dot.NewDot(50, "dot-svg").Renderer,
},
ext.RenderMap{
Languages: []string{"uml-svg"},
RenderFunction: uml.NewUML(50, "uml-svg").Renderer,
},
ext.RenderMap{
Languages: []string{"python-output"},
RenderFunction: python.NewPython(50, "python3", "python-output").Renderer,
},
ext.RenderMap{
Languages: []string{"*"},
RenderFunction: ext.GetFencedCodeBlockRendererFunc(
highlighting.NewHTMLRenderer(
highlighting.WithGuessLanguage(true),
highlighting.WithStyle("trac"),
),
),
},
)
ext.NewExt()
will combine fenced codeblock extensions as one extension, and accounding ext.RenderMap.Languages
to decide which renderer will be used.
See more:
- OhYee#2
- https://github.com/OhYee/goldmark-plantuml/blob/master/demo/demo2/main.go
- https://github.com/OhYee/blotter/blob/7f1426754ded43db9471fb8f1d8e7edd78dcdc68/api/pkg/markdown/main.go#L24-L92
There are two demo(using '
instead of ′ in the code block)
- default config
'''go
package main
import ()
func main(){}
'''
'''plantuml
@startuml
Alice -> Bob: test
@enduml
'''
- using
plantuml-svg
and goldmark-highlighting extension
'''go
package main
import ()
func main(){}
'''
'''plantuml-svg
@startuml
Alice -> Bob: test
@enduml
'''
go get -u github.com/OhYee/goldmark-plantuml