diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-14 17:50:33 +0000 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-14 17:50:33 +0000 |
| commit | 3312977ebeff03edc5b1bc1a2f815cad6a1ba7b8 (patch) | |
| tree | 419617345dba2da3d0b666d5993964ce75904efa /markdown/eval.go | |
| parent | 8edad5f9aee4625384485ad07180da751858839c (diff) | |
| parent | 0c0c6fb6df755d8f53d353e8b941e22a6c474b60 (diff) | |
Merge pull request '[Feat] Custom replace' (#3) from feat/custom-replace into main
Reviewed-on: https://git.anhgelus.world/anhgelus/small-web/pulls/3
Diffstat (limited to 'markdown/eval.go')
| -rw-r--r-- | markdown/eval.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/markdown/eval.go b/markdown/eval.go index 376e577..ae4bafc 100644 --- a/markdown/eval.go +++ b/markdown/eval.go @@ -1,18 +1,16 @@ package markdown -import "html/template" +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) { - lxs := lex(s) - tree, err := ast(lxs) - if err != nil { - return "", err - } if opt == nil { opt = new(Option) } @@ -22,6 +20,14 @@ func Parse(s string, opt *Option) (template.HTML, *ParseError) { 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) } |
