aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_code.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-13 17:15:47 +0000
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-13 17:15:47 +0000
commit62fa3f77e8215fdaaf72ddb9df4162e0d65148da (patch)
treedbf20dca933996cf253fe2d110d8381b0c407b2d /markdown/ast_code.go
parentae297bbd117835304b298e7d8a2f914111940e77 (diff)
parent48311424ba2eaac254864c008b6d18e8510f827d (diff)
Merge pull request '[Refactor] Replace manual DOM manipulation in markdown by cleaner one' (#2) from refactor/mardown-dom into main
Reviewed-on: https://git.anhgelus.world/anhgelus/small-web/pulls/2
Diffstat (limited to 'markdown/ast_code.go')
-rw-r--r--markdown/ast_code.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/markdown/ast_code.go b/markdown/ast_code.go
index 6980f32..c83a984 100644
--- a/markdown/ast_code.go
+++ b/markdown/ast_code.go
@@ -2,8 +2,10 @@ package markdown
import (
"errors"
- "fmt"
+ "html"
"html/template"
+
+ "git.anhgelus.world/anhgelus/small-web/dom"
)
var (
@@ -26,11 +28,15 @@ type astCode struct {
}
func (a *astCode) Eval(_ *Option) (template.HTML, *ParseError) {
+ content := template.HTML(html.EscapeString(a.content))
switch a.codeType {
case codeOneLine:
- return template.HTML(fmt.Sprintf("<code>%s</code>", template.HTMLEscapeString(a.content))), nil
+ return dom.NewLiteralContentElement("code", content).Render(), nil
case codeMultiLine:
- return template.HTML(fmt.Sprintf("<pre><code>%s</code></pre>", template.HTMLEscapeString(a.content))), nil
+ pre := dom.NewContentElement("pre", make([]dom.Element, 1))
+ code := dom.NewContentElement("code", []dom.Element{dom.NewLiteralElement(content)})
+ pre.Contents[0] = code
+ return pre.Render(), nil
default:
return "", &ParseError{lxs: lexers{}, internal: ErrUnknownCodeType}
}