uml

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 8 Imported by: 0

README

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

Documentation

Overview

Package uml is a extension for the goldmark(http://github.com/yuin/goldmark).

This extension adds svg picture output from uml language using go-plantuml(OhYee/go-plantuml).

Index

Constants

This section is empty.

Variables

View Source
var Default = NewUMLExtension(50, "plantuml")

Default uml extension when there is no other fencedCodeBlock goldmark render extensions

Functions

func NewUMLExtension

func NewUMLExtension(length int, languages ...string) goldmark.Extender

NewUMLExtension return the goldmark.Extender

func RenderMap

func RenderMap(length int, languages ...string) ext.RenderMap

RenderMap return the goldmark-fenced_codeblock_extension.RenderMap

Types

type UML

type UML struct {
	Languages []string

	MaxLength int
	// contains filtered or unexported fields
}

UML render struct

func NewUML

func NewUML(length int, languages ...string) *UML

NewUML initial a UML struct

func (*UML) Renderer

func (u *UML) Renderer(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error)

Renderer render function

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL