diff options
| author | William Hergès <william@herges.fr> | 2025-10-03 22:22:40 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-10-03 22:22:40 +0200 |
| commit | 40b1f53362105a495c6a486f3488e83d79eb582a (patch) | |
| tree | b84609a49ad55881d0e54f72a474d3bbb1db31ae /markdown/eval.go | |
| parent | ce6a2da035dc045510157a0eeefaebf56f0e8958 (diff) | |
feat(markdown): eval option to setup custom image source func
Diffstat (limited to 'markdown/eval.go')
| -rw-r--r-- | markdown/eval.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/markdown/eval.go b/markdown/eval.go index db9d150..56bb989 100644 --- a/markdown/eval.go +++ b/markdown/eval.go @@ -2,15 +2,25 @@ package markdown import "html/template" -func Parse(s string) (template.HTML, *ParseError) { +type Option struct { + ImageSource func(string) string +} + +func Parse(s string, opt *Option) (template.HTML, *ParseError) { lxs := lex(s) tree, err := ast(lxs) if err != nil { return "", err } - return tree.Eval() + if opt == nil { + opt = new(Option) + } + if opt.ImageSource == nil { + opt.ImageSource = func(s string) string { return s } + } + return tree.Eval(opt) } -func ParseBytes(b []byte) (template.HTML, *ParseError) { - return Parse(string(b)) +func ParseBytes(b []byte, opt *Option) (template.HTML, *ParseError) { + return Parse(string(b), opt) } |
