pikchr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 9 Imported by: 2

README

Go Reference Go

goldmark-pikchr is an extension for the goldmark Markdown parser that adds support for pikchr diagrams.

Usage

To use goldmark-pikchr, import the pikchr package.

import pikchr "github.com/jchenry/goldmark-pikchr"

Then include the pikchr.Extender in the list of extensions you build your goldmark.Markdown with.

goldmark.New(
  &pikchr.Extender{}
  // ...
).Convert(src, out)

The package supports pikchr diagrams inside fenced code blocks with the language pikchr. For example,

```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
```

When you render the Markdown as HTML, these will be replaced with SVG blocks. pikchr will render these into diagrams client-side.

Code is based on github.com/abhinav/goldmark-mermaid and licensed under the same terms.

Documentation

Overview

Package pikchr adds support for pikchr diagrams to the Goldmark Markdown parser.

Index

Constants

This section is empty.

Variables

View Source
var Kind = ast.NewNodeKind("PikchrBlock")

Kind is the kind of a pikchr block.

Functions

This section is empty.

Types

type Block

type Block struct {
	ast.BaseBlock
}

Block is a pikchr block.

```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)" fi	t
```

Its raw contents are the plain text of the pikchr diagram.

func (*Block) Dump

func (b *Block) Dump(src []byte, level int)

Dump dumps the contents of this block to stdout.

func (*Block) IsRaw

func (*Block) IsRaw() bool

IsRaw reports that this block should be rendered as-is.

func (*Block) Kind

func (*Block) Kind() ast.NodeKind

Kind reports that this is a pikchrBlock.

type Extender

type Extender struct {
	DarkMode bool
}

Extender adds support for pikchr diagrams to a Goldmark Markdown parser.

Use it by installing it to the goldmark.Markdown object upon creation.

goldmark.New(
  // ...
  goldmark.WithExtensions(
    // ...
    &pikchr.Exender{},
  ),
)

func (*Extender) Extend

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

Extend extends the provided Goldmark parser with support for pikchr diagrams.

type Renderer

type Renderer struct {
	DarkMode bool
}

Renderer renders pikchr diagrams as HTML, to be rendered into images client side.

func (*Renderer) RegisterFuncs

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

RegisterFuncs registers the renderer for pikchr blocks with the provided Goldmark Registerer.

func (*Renderer) Render

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

Render renders pikchr.Block nodes.

type Transformer

type Transformer struct{}

Transformer transforms a Goldmark Markdown AST with support for pikchr diagrams by replacing pikchr code blocks with Block nodes.

func (*Transformer) Transform

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

Transform transforms the provided Markdown AST.

Jump to

Keyboard shortcuts

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