-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathmathlatex.go
More file actions
58 lines (47 loc) · 1.75 KB
/
mathlatex.go
File metadata and controls
58 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package renderer
import (
"fmt"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/util"
cparser "github.com/kovetskiy/mark/parser"
)
type ConfluenceMathLatexRenderer struct {
html.Config
}
// NewConfluenceRenderer creates a new instance of the ConfluenceRenderer
func NewConfluenceMathLatexRenderer(opts ...html.Option) renderer.NodeRenderer {
return &ConfluenceMathLatexRenderer{
Config: html.NewConfig(),
}
}
// RegisterFuncs implements NodeRenderer.RegisterFuncs .
func (r *ConfluenceMathLatexRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
reg.Register(cparser.KindMathLatexInline, r.renderInline)
reg.Register(cparser.KindMathLatexBlock, r.renderBlock)
}
func (r *ConfluenceMathLatexRenderer) renderInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
if entering {
node := n.(*cparser.MathLatexInline)
quoteType := "ppl mathjax inline macro"
w.WriteString(fmt.Sprintf("<ac:structured-macro ac:name=\"%s\">", quoteType))
w.WriteString("<ac:parameter ac:name=\"equation\">")
w.Write(node.Equation)
w.WriteString("</ac:parameter>")
w.WriteString("</ac:structured-macro>")
}
return ast.WalkContinue, nil
}
func (r *ConfluenceMathLatexRenderer) renderBlock(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
if entering {
node := n.(*cparser.MathLatexBlock)
quoteType := "ppl mathjax block macro"
w.WriteString(fmt.Sprintf("<ac:structured-macro ac:name=\"%s\">", quoteType))
w.WriteString("<ac:plain-text-body><![CDATA[")
w.Write(node.Equation)
w.WriteString("]]></ac:plain-text-body>")
w.WriteString("</ac:structured-macro>")
}
return ast.WalkContinue, nil
}