diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-12 19:21:22 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-12 19:21:22 +0100 |
| commit | a815c291074b454d4bb1a31067cd363c84df1360 (patch) | |
| tree | b04e3e048fdd15caff2c9127d7598b04b47178a7 /markdown | |
| parent | d56090d43c925dbbd22a3e0c3f6d541674a09697 (diff) | |
refactor(frontend): remove JS files
Diffstat (limited to 'markdown')
| -rw-r--r-- | markdown/ast_external.go | 6 | ||||
| -rw-r--r-- | markdown/eval.go | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/markdown/ast_external.go b/markdown/ast_external.go index ee00eab..8adeea1 100644 --- a/markdown/ast_external.go +++ b/markdown/ast_external.go @@ -6,7 +6,7 @@ import ( "regexp" ) -var externalLink = regexp.MustCompile(`https?://`) +var ExternalLink = regexp.MustCompile(`https?://`) type astLink struct { content block @@ -23,7 +23,7 @@ func (a *astLink) Eval(opt *Option) (template.HTML, *ParseError) { if err != nil { return "", err } - rr := RenderLink(string(content), string(href)) + rr := opt.RenderLink(string(content), string(href)) if a.addSpace { return " " + rr, nil } @@ -31,7 +31,7 @@ func (a *astLink) Eval(opt *Option) (template.HTML, *ParseError) { } func RenderLink(content, href string) template.HTML { - if !externalLink.Match([]byte(href)) { + if !ExternalLink.Match([]byte(href)) { return template.HTML(fmt.Sprintf(`<a href="%s">%s</a>`, href, content)) } return template.HTML(fmt.Sprintf(`<a href="%s" target="_blank" rel="noreferer">%s</a>`, href, content)) diff --git a/markdown/eval.go b/markdown/eval.go index 56bb989..376e577 100644 --- a/markdown/eval.go +++ b/markdown/eval.go @@ -3,7 +3,8 @@ package markdown import "html/template" type Option struct { - ImageSource func(string) string + ImageSource func(source string) string + RenderLink func(content, href string) template.HTML } func Parse(s string, opt *Option) (template.HTML, *ParseError) { @@ -18,6 +19,9 @@ func Parse(s string, opt *Option) (template.HTML, *ParseError) { if opt.ImageSource == nil { opt.ImageSource = func(s string) string { return s } } + if opt.RenderLink == nil { + opt.RenderLink = RenderLink + } return tree.Eval(opt) } |
