Skip to content

OhYee/goldmark-plantuml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goldmark-plantuml

Sync to Gitee w orkflow state codecov version

goldmark-plantuml is an extension for goldmark.

You can plantuml to build svg image in your markdown like mume

Usage

Only use this extension

goldmark.New( 
  goldmark.WithExtensions( 
    extension.GFM, 
    uml.Default, 
  ), 
  goldmark.WithParserOptions( 
    parser.WithAutoHeadingID(), 
  ), 
  goldmark.WithRendererOptions(), 
 ) 

Use with other fenced codeblock extensions

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:

screenshot

There are two demo(using ' instead of ′ in the code block)

  1. default config

Demo1 Output1

'''go
package main

import ()

func main(){}
'''

'''plantuml
@startuml
Alice -> Bob: test
@enduml
'''

  1. using plantuml-svg and goldmark-highlighting extension

Demo2 Output2

'''go
package main

import ()

func main(){}
'''

'''plantuml-svg
@startuml
Alice -> Bob: test
@enduml
'''

Installation

go get -u github.com/OhYee/goldmark-plantuml

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published