katex

package module
v0.0.0-...-1c40021 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 13 Imported by: 2

README

Goldmark Katex

Go Reference

Goldmark Katex is a Goldmark extension providing math and equation support through KaTeX.

Usage

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

Wrap inline math with a pair of single $:

$A$

Wrap block math with a pair of double $:

$$
A = \pi \times r^2
$$

Example

Given the radius $r$ of a circle, the area $A$ is:

$$
A = \pi \times r^2
$$

And the circumference $C$ is:

$$
C = 2 \pi r
$$

More Goldmark Extensions

  • D2: diagram support through D2

Documentation

Index

Examples

Constants

This section is empty.

Variables

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

Functions

func Render

func Render(w io.Writer, src []byte, display bool) error
Example
b := bytes.Buffer{}
Render(&b, []byte(`Y = A \dot X^2 + B \dot X + C`), false)
fmt.Println(b.String())
Output:

<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi><mo>=</mo><mi>A</mi><msup><mover accent="true"><mi>X</mi><mo>˙</mo></mover><mn>2</mn></msup><mo>+</mo><mi>B</mi><mover accent="true"><mi>X</mi><mo>˙</mo></mover><mo>+</mo><mi>C</mi></mrow><annotation encoding="application/x-tex">Y = A \dot X^2 + B \dot X + C</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal">A</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9202em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span><span style="top:-3.2523em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.0556em;"><span class="mord">˙</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9202em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span><span style="top:-3.2523em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.0556em;"><span class="mord">˙</span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>

Types

type Block

type Block struct {
	ast.BaseInline

	Equation []byte
}

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 HTMLRenderer

type HTMLRenderer struct {
	html.Config
	// contains filtered or unexported fields
}

func (*HTMLRenderer) RegisterFuncs

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

type Inline

type Inline struct {
	ast.BaseInline

	Equation []byte
}

func (*Inline) Dump

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

func (*Inline) Inline

func (n *Inline) Inline()

func (*Inline) IsBlank

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

func (*Inline) Kind

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

type Parser

type Parser struct {
}

func (*Parser) Parse

func (s *Parser) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.Node

func (*Parser) Trigger

func (s *Parser) Trigger() []byte

Jump to

Keyboard shortcuts

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