aboutsummaryrefslogtreecommitdiff
path: root/markdown/eval.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-14 18:05:35 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-14 18:05:35 +0100
commita65b9cb6b2c7dc7b48b8076d5e463776f1de0cf1 (patch)
tree021a5d38fe1a6c9bd876114fd3b3f4a296737fbd /markdown/eval.go
parent8edad5f9aee4625384485ad07180da751858839c (diff)
feat(markdown): custom replacer
Diffstat (limited to 'markdown/eval.go')
-rw-r--r--markdown/eval.go18
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)
}