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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright 2023 The goldmark-figure authors
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
package ast
import (
gast "github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/util"
)
// KindFigure is a NodeKind of the Figure node.
var KindFigure = gast.NewNodeKind("Figure")
// A Figure struct represents a table of Markdown(GFM) text.
type Figure struct {
gast.BaseBlock
}
// Kind implements Node.Kind.
func (n *Figure) Kind() gast.NodeKind {
return KindFigure
}
// Dump implements Node.Dump
func (n *Figure) Dump(source []byte, level int) {
gast.DumpHelper(n, source, level, nil, func(level int) {
})
}
// NewFigure returns a new Table node.
func NewFigure() *Figure {
return &Figure{}
}
// KindFigureImage is a NodeKind of the FigureImage node.
var KindFigureImage = gast.NewNodeKind("FigureImage")
// A FigureImage struct represents a table of Markdown(GFM) text.
type FigureImage struct {
gast.BaseBlock
}
// Kind implements Node.Kind.
func (n *FigureImage) Kind() gast.NodeKind {
return KindFigureImage
}
// Dump implements Node.Dump
func (n *FigureImage) Dump(source []byte, level int) {
gast.DumpHelper(n, source, level, nil, func(level int) {
})
}
// NewFigureImage returns a new Table node.
func NewFigureImage() *FigureImage {
return &FigureImage{}
}
// KindFigureCaption is a NodeKind of the FigureCaption node.
var KindFigureCaption = gast.NewNodeKind("FigureCaption")
// A FigureCaption struct represents a table of Markdown(GFM) text.
type FigureCaption struct {
gast.BaseBlock
}
// Kind implements Node.Kind.
func (n *FigureCaption) Kind() gast.NodeKind {
return KindFigureCaption
}
// Dump implements Node.Dump
func (n *FigureCaption) Dump(source []byte, level int) {
gast.DumpHelper(n, source, level, nil, func(level int) {
})
}
// NewFigureCaption returns a new Table node.
func NewFigureCaption() *FigureCaption {
return &FigureCaption{}
}
// FigureHTMLRenderer is a renderer.NodeRenderer implementation that
// renders Figure nodes.
type FigureHTMLRenderer struct {
}
// NewFigureHTMLRenderer returns a new FigureHTMLRenderer.
func NewFigureHTMLRenderer() renderer.NodeRenderer {
return &FigureHTMLRenderer{}
}
// RegisterFuncs implements renderer.NodeRenderer.RegisterFuncs.
func (r *FigureHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
reg.Register(KindFigure, r.renderFigure)
reg.Register(KindFigureCaption, r.renderFigureCaption)
}
func (r *FigureHTMLRenderer) renderFigure(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
if entering {
_, _ = w.WriteString("<figure>\n")
} else {
_, _ = w.WriteString("</figure>\n")
}
return gast.WalkContinue, nil
}
func (r *FigureHTMLRenderer) renderFigureCaption(w util.BufWriter, source []byte, n gast.Node, entering bool) (gast.WalkStatus, error) {
if entering {
_, _ = w.WriteString("<figcaption><p>")
} else {
_, _ = w.WriteString("</p></figcaption>\n")
}
return gast.WalkContinue, nil
}
|