aboutsummaryrefslogtreecommitdiff
path: root/markdown/eval.go
diff options
context:
space:
mode:
authorWilliam Hergès <william@herges.fr>2025-10-03 22:22:40 +0200
committerWilliam Hergès <william@herges.fr>2025-10-03 22:22:40 +0200
commit40b1f53362105a495c6a486f3488e83d79eb582a (patch)
treeb84609a49ad55881d0e54f72a474d3bbb1db31ae /markdown/eval.go
parentce6a2da035dc045510157a0eeefaebf56f0e8958 (diff)
feat(markdown): eval option to setup custom image source func
Diffstat (limited to 'markdown/eval.go')
-rw-r--r--markdown/eval.go18
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)
}