pikchr

package module
v0.0.0-...-c85207b Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 9 Imported by: 0

README

Pikchr for Goldmark

This is an extension for Goldmark that adds support for generating figures using Pikchr. It doesn't rely on cgo or an external binary, instead using the wazero WebAssembly runtime to embed Pikchr.

Usage

Register the extension:

goldmark.New(
	goldmark.WithExtensions(&pikchr.Extender{}),
).Convert(src, dst)

Fenced code blocks like below will now be rendered using Pikchr:

```pikchr
arrow right 200% "Markdown" "Source"
box rad 10px "Markdown" "Formatter" "(markdown.c)" fit
arrow right 200% "HTML+SVG" "Output"
arrow <-> down 70% from last box.s
box same "Pikchr" "Formatter" "(pikchr.c)" fit
```

Resulting in a figure like below:

Performance

Performance will be the same as for the underlying go-pikchr package. For a small Pikchr figure, go-pikchr takes about 7.5ms:

$ go test -test.bench .
goos: linux
goarch: amd64
pkg: github.com/rigtorp/go-pikchr
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkPikchr-8            142           7520289 ns/op
PASS
ok      github.com/rigtorp/go-pikchr    1.471s

Acknowledgements

This extension is based on the goldmark-pikchr extension by Colin Henry and the goldmark-d2 extension by Furqan Software.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindBlock = ast.NewNodeKind("Block")

Functions

This section is empty.

Types

type Block

type Block struct {
	ast.BaseBlock
}

func (*Block) Dump

func (n *Block) Dump(source []byte, level int)

func (*Block) IsBlank

func (n *Block) IsBlank(source []byte) bool

func (*Block) Kind

func (n *Block) Kind() ast.NodeKind

type Extender

type Extender struct{}

func (*Extender) Extend

func (e *Extender) Extend(m goldmark.Markdown)

type Renderer

type Renderer struct{}

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

func (*Renderer) Render

func (r *Renderer) Render(w util.BufWriter, src []byte, node ast.Node, entering bool) (ast.WalkStatus, error)

type Transformer

type Transformer struct {
}

func (*Transformer) Transform

func (s *Transformer) Transform(doc *ast.Document, reader text.Reader, pctx parser.Context)

Jump to

Keyboard shortcuts

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