-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure.go
42 lines (36 loc) · 1.08 KB
/
figure.go
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
// 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 figure
import (
"github.com/yuin/goldmark"
aparser "github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/util"
"github.com/mangoumbrella/goldmark-figure/ast"
fparser "github.com/mangoumbrella/goldmark-figure/parser"
)
type extension struct {
renderImageLink bool
}
// Figure is an extension to render <figure> elements.
var Figure = &extension{}
func (f *extension) WithImageLink() *extension {
f.renderImageLink = true
return f
}
func (f *extension) Extend(m goldmark.Markdown) {
m.Parser().AddOptions(
aparser.WithParagraphTransformers(
util.Prioritized(fparser.NewFigureParagraphTransformer(), 120),
),
aparser.WithASTTransformers(
util.Prioritized(fparser.NewFigureASTTransformer(), 0),
),
)
m.Renderer().AddOptions(renderer.WithNodeRenderers(
util.Prioritized(ast.NewFigureHTMLRenderer(f.renderImageLink), 0),
))
}