Documentation
¶
Index ¶
- Variables
- func Render(w io.Writer, src []byte, display bool, throwOnError bool) error
- type Block
- type BlockParser
- func (b *BlockParser) CanAcceptIndentedLine() bool
- func (b *BlockParser) CanInterruptParagraph() bool
- func (b *BlockParser) Close(node ast.Node, reader text.Reader, pc parser.Context)
- func (b *BlockParser) Continue(node ast.Node, reader text.Reader, pc parser.Context) parser.State
- func (b *BlockParser) Open(parent ast.Node, reader text.Reader, pc parser.Context) (ast.Node, parser.State)
- func (b *BlockParser) Trigger() []byte
- type Extender
- type HTMLRenderer
- type Inline
- type Parser
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var KindBlock = ast.NewNodeKind("Block")
var KindInline = ast.NewNodeKind("Inline")
Functions ¶
func Render ¶
Example ¶
b := bytes.Buffer{}
Render(&b, []byte(`Y = A \dot X^2 + B \dot X + C`), false, 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="katex-base"><span class="katex-strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.2222em;">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="katex-base"><span class="katex-strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal">A</span><span class="mord"><span class="mord katex-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.0785em;">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="katex-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="katex-base"><span class="katex-strut" style="height:1.0035em;vertical-align:-0.0833em;"></span><span class="mord mathnormal" style="margin-right:0.0502em;">B</span><span class="mord katex-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.0785em;">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="katex-base"><span class="katex-strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.0715em;">C</span></span></span></span>
Types ¶
type Block ¶
Block is display math occupying whole lines of its own ("$$...$$").
BlockParser builds it during block parsing, before Markdown ever looks at the equation. Parsing it inline instead let block constructs mangle multi-line equations first: a line followed by "=" became a Setext heading, and the equation was silently truncated at the heading. The equation body is held in Lines(), and IsRaw keeps Markdown away from it.
Display math written in the middle of a line stays inline math; see Parser.
type BlockParser ¶
type BlockParser struct {
}
BlockParser parses display math ("$$...$$") that begins a line.
Running at the block level keeps the equation opaque to Markdown, so an equation of any length survives intact. Parsed inline it would first be cut up by block parsing, most visibly by a line followed by "=" becoming a Setext heading, which truncated the equation at that point.
A "$$" that begins a line opens a block, which runs to the next "$$" or to end of input, as a fenced code block does. Text before the opening delimiter or after the closing one is never consumed: display math written mid-line is left to the inline Parser, which renders it in place.
func (*BlockParser) CanAcceptIndentedLine ¶
func (b *BlockParser) CanAcceptIndentedLine() bool
func (*BlockParser) CanInterruptParagraph ¶
func (b *BlockParser) CanInterruptParagraph() bool
func (*BlockParser) Trigger ¶
func (b *BlockParser) Trigger() []byte
type HTMLRenderer ¶
func (*HTMLRenderer) RegisterFuncs ¶
func (r *HTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
type Inline ¶
type Inline struct {
ast.BaseInline
Equation []byte
// Display selects KaTeX display mode, set for "$$...$$".
Display bool
}
Inline is math that sits within a line of text.
It covers inline math ("$...$") and display math written mid-line ("text $$x$$ more"), which stays an inline node so it nests validly inside the surrounding paragraph. Display math on a line of its own is a Block.
type Parser ¶
type Parser struct {
}
Parser is the inline parser for math delimited by dollar signs.
It handles inline math ("$...$") and display math written in the middle of a line ("text $$x$$ more"). Display math that begins a line is claimed earlier by BlockParser, so it never reaches this parser; what is left here is always confined to a single line.
