blob: ae4bafc4b6e5b9818cbe807fc8bfe17fe3a1e40e (
plain)
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
|
package markdown
import (
"html/template"
)
type Option struct {
ImageSource func(source string) string
RenderLink func(content, href string) template.HTML
Replaces map[rune]string
}
func Parse(s string, opt *Option) (template.HTML, *ParseError) {
if opt == nil {
opt = new(Option)
}
if opt.ImageSource == nil {
opt.ImageSource = func(s string) string { return s }
}
if opt.RenderLink == nil {
opt.RenderLink = RenderLink
}
if opt.Replaces == nil {
opt.Replaces = make(map[rune]string, 0)
}
lxs := lex(s, opt)
tree, err := ast(lxs)
if err != nil {
return "", err
}
return tree.Eval(opt)
}
func ParseBytes(b []byte, opt *Option) (template.HTML, *ParseError) {
return Parse(string(b), opt)
}
|