mermaid

package module
v0.0.0-...-3ab53e3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 14 Imported by: 0

README

goldmark-mermaid

Copy for goldmark-mathjax. Used by mdserver.

Installation

go get github.com/kingreatwill/goldmark-mermaid

Usage

package main

import (
	"bytes"
	"fmt"

	mermaid "github.com/kingreatwill/goldmark-mermaid"
	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/parser"
	"github.com/yuin/goldmark/renderer/html"
)

func main() {
	md := goldmark.New(
		goldmark.WithExtensions(mermaid.Mermaid),
		goldmark.WithParserOptions(
			parser.WithAutoHeadingID(),
		),
		goldmark.WithRendererOptions(
			html.WithHardWraps(),
			html.WithXHTML(),
		),
	)

	// todo more control on the parsing process
	var html bytes.Buffer
	mdContent := []byte(`
$$
\mathbb{E}(X) = \int x d F(x) = \left\{ \begin{aligned} \sum_x x f(x) \; & \text{ if } X \text{ is discrete} 
\\ \int x f(x) dx \; & \text{ if } X \text{ is continuous }
\end{aligned} \right.
$$


Inline math $\frac{1}{2}$
`)
	if err := md.Convert(mdContent, &html); err != nil {
		fmt.Println(err)
	}
	fmt.Println(html.String())
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindInlineMath = ast.NewNodeKind("InlineMath")
View Source
var KindMathBlock = ast.NewNodeKind("MathBLock")
View Source
var Mermaid = &mermaid{
	inlineStartDelim: `\(`,
	inlineEndDelim:   `\)`,
	blockStartDelim:  `\[`,
	blockEndDelim:    `\]`,
}
View Source
var Tex = &tex{
	texRenderer: NewDefaultTexRenderer(),
}

Functions

func NewInlineMathParser

func NewInlineMathParser() parser.InlineParser

func NewInlineMathRenderer

func NewInlineMathRenderer(start, end string) renderer.NodeRenderer

func NewMathBlockRenderer

func NewMathBlockRenderer(start, end string) renderer.NodeRenderer

func NewMathJaxBlockParser

func NewMathJaxBlockParser() parser.BlockParser

func NewMermaid

func NewMermaid(opts ...Option) *mermaid

Types

type InlineMath

type InlineMath struct {
	ast.BaseInline
}

func NewInlineMath

func NewInlineMath() *InlineMath

func (*InlineMath) Dump

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

func (*InlineMath) Inline

func (n *InlineMath) Inline()

func (*InlineMath) IsBlank

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

func (*InlineMath) Kind

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

type InlineMathRenderer

type InlineMathRenderer struct {
	// contains filtered or unexported fields
}

func (*InlineMathRenderer) RegisterFuncs

type InlineTexMathRenderer

type InlineTexMathRenderer struct {
	// contains filtered or unexported fields
}

func (*InlineTexMathRenderer) RegisterFuncs

type MathBlock

type MathBlock struct {
	ast.BaseBlock
}

func NewMathBlock

func NewMathBlock() *MathBlock

func (*MathBlock) Dump

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

func (*MathBlock) IsRaw

func (n *MathBlock) IsRaw() bool

func (*MathBlock) Kind

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

type MathBlockRenderer

type MathBlockRenderer struct {
	// contains filtered or unexported fields
}

func (*MathBlockRenderer) RegisterFuncs

type MathTexBlockRenderer

type MathTexBlockRenderer struct {
	// contains filtered or unexported fields
}

func (*MathTexBlockRenderer) RegisterFuncs

type Option

type Option interface {
	SetOption(e *mermaid)
}

func WithBlockDelim

func WithBlockDelim(start string, end string) Option

func WithInlineDelim

func WithInlineDelim(start string, end string) Option

type TexRenderer

type TexRenderer struct {
	// contains filtered or unexported fields
}

func NewDefaultTexRenderer

func NewDefaultTexRenderer() *TexRenderer

func (*TexRenderer) Run

func (r *TexRenderer) Run(formula string) []byte

func (*TexRenderer) RunInline

func (r *TexRenderer) RunInline(formula string) []byte

Jump to

Keyboard shortcuts

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