-
Notifications
You must be signed in to change notification settings - Fork 7
/
extender.go
38 lines (34 loc) · 1014 Bytes
/
extender.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
package wikilink
import (
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/util"
)
// Extender extends a goldmark Markdown object with support for parsing and
// rendering Wikilinks.
type Extender struct {
// Resoler specifies how to resolve destinations for linked pages.
//
// Uses DefaultResolver if unspecified.
Resolver Resolver
}
// Extend extends the provided Markdown object with support for wikilinks.
func (e *Extender) Extend(md goldmark.Markdown) {
// The link parser is at priority 200 in goldmark so we need to be
// lower than that to ensure that the "[" trigger fires.
md.Parser().AddOptions(
parser.WithInlineParsers(
util.Prioritized(&Parser{}, 199),
),
)
// The renderer priority matters less. Use the same just so that
// there's a reasonable expected value.
md.Renderer().AddOptions(
renderer.WithNodeRenderers(
util.Prioritized(&Renderer{
Resolver: e.Resolver,
}, 199),
),
)
}