-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.go
60 lines (54 loc) · 1.7 KB
/
markdown.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package tg
import (
"github.com/skunkie/goldmark-tg/extension"
"github.com/skunkie/goldmark-tg/renderer/html"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/util"
)
func blockParsers() []util.PrioritizedValue {
return []util.PrioritizedValue{
util.Prioritized(parser.NewCodeBlockParser(), 500),
util.Prioritized(parser.NewFencedCodeBlockParser(), 700),
util.Prioritized(parser.NewBlockquoteParser(), 800),
util.Prioritized(parser.NewParagraphParser(), 1000),
}
}
func inlineParsers() []util.PrioritizedValue {
return []util.PrioritizedValue{
util.Prioritized(parser.NewCodeSpanParser(), 100),
util.Prioritized(parser.NewLinkParser(), 200),
}
}
func tgParser() parser.Parser {
return parser.NewParser(
parser.WithBlockParsers(blockParsers()...),
parser.WithInlineParsers(inlineParsers()...),
)
}
// A collection of goldmark options to parse and render Telegram Markdown.
func Markdown() []goldmark.Option {
return []goldmark.Option{
goldmark.WithExtensions(extension.TGM),
goldmark.WithParser(tgParser()),
goldmark.WithRendererOptions(
renderer.WithNodeRenderers(
util.PrioritizedValue{Value: html.NewParagraphHTMLRenderer(), Priority: 500},
),
),
}
}
// A collection of goldmark options to parse and render Telegram MarkdownV2.
func MarkdownV2() []goldmark.Option {
return []goldmark.Option{
goldmark.WithExtensions(extension.TGMV2),
goldmark.WithParser(tgParser()),
goldmark.WithRendererOptions(
renderer.WithNodeRenderers(
util.PrioritizedValue{Value: html.NewEmojiHTMLRenderer(), Priority: 500},
util.PrioritizedValue{Value: html.NewParagraphHTMLRenderer(), Priority: 500},
),
),
}
}