aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_code.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-13 18:09:40 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-13 18:09:48 +0100
commitaea07c141b3a2448ea367ad80ad5e12d04a78df7 (patch)
tree67031a6cfe4c5b42f9527410045f4d3793f32946 /markdown/ast_code.go
parentd695b39edf898e056a8de3724a020f15754fcea9 (diff)
refactor(markdown): use new dom package to create html
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}
}