pikchr

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

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 9 Imported by: 1

README

goldmark-pikchr

Goldmark extension for rendering pikchr diagrams. Heavily copied from github.com/abhinav/goldmark-mermaid. Uses gopikchr for translating pikchr diagrams to svg.

Syntax

A simple pikchr diagram:

```pikchr
box color red wid 2.6in \
    "Click on any diagram on this page" big \
    "to see the Pikchr source text" big
```
Attributes

The pikchr plugin supports the following attributes:

  • toggle (default false): if true, add javascript to the page to toggle between the diagram and its source when it is clicked.
  • limitwidth (default true): if true, add a max-width style limiting the maximum width of the <div> containing the <svg> element to the width of the diagram. This prevents it from getting scaled up.

Configuration

Add a &pikchr.Extender{} to the list of goldmark extensions:

gm := goldmark.New(goldmark.WithExtensions(&pikchr.Extender{}))

If you wish to use the toggle attribute, add the following snippet to your css:

.hidden {
   position: absolute !important;
   opacity: 0 !important;
   pointer-events: none !important;
   display: none !important;
}

TODOs

  • Enable click-to-toggle-source as on pikchr.org examples
  • Add a toggle parameter to the pikchr blocks, so toggling source can be turned on or off per block
  • Add a limitwidth parameter so that max-width styling can be turned off.

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.

View Source
var ScriptKind = ast.NewNodeKind("PikchrScriptBlock")

ScriptKind is the kind of a Pikchr Script block.

Functions

This section is empty.

Types

type Block

type Block struct {
	ast.FencedCodeBlock
	// contains filtered or unexported fields
}

Block is a Pikchr block.

```pikchr
box color red wid 2.6in \
    "Click on any diagram on this page" big \
    "to see the Pikchr source text" big
```

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{}

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 ImmutableAttributes

type ImmutableAttributes interface {
	// Get returns (value, true) if an attribute associated with given
	// name exists, otherwise (nil, false)
	Get(name []byte) (interface{}, bool)

	// GetString returns (value, true) if an attribute associated with given
	// name exists, otherwise (nil, false)
	GetString(name string) (interface{}, bool)

	// All returns all attributes.
	All() []ast.Attribute
}

ImmutableAttributes is a read-only interface for ast.Attributes.

type Renderer

type Renderer struct {
}

Renderer renders Pikchr diagrams as HTML/SVG.

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 (*Renderer) Render(w util.BufWriter, src []byte, node ast.Node, entering bool) (ast.WalkStatus, error)

Render renders pikchr.Block nodes.

func (*Renderer) RenderScript

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

RenderScript renders pikchr.ScriptBlock nodes.

type ScriptBlock

type ScriptBlock struct {
	ast.BaseBlock
	// contains filtered or unexported fields
}

ScriptBlock marks where the Pikchr Javascript will be included.

This is a placeholder and does not contain anything.

func (*ScriptBlock) Dump

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

Dump dumps the contents of this block to stdout.

func (*ScriptBlock) IsRaw

func (*ScriptBlock) IsRaw() bool

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

func (*ScriptBlock) Kind

func (*ScriptBlock) Kind() ast.NodeKind

Kind reports that this is a PikchrScriptBlock.

type Transformer

type Transformer struct {
}

Transformer transforms a Goldmark Markdown AST with support for Pikchr diagrams. It makes the following transformations:

  • replace pikchr code blocks with pikchr.Block nodes
  • add a pikchr.ScriptBlock node if the document uses Pikchr

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