aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_quote.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_quote.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_quote.go')
-rw-r--r--markdown/ast_quote.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/markdown/ast_quote.go b/markdown/ast_quote.go
index fa3a878..96669c5 100644
--- a/markdown/ast_quote.go
+++ b/markdown/ast_quote.go
@@ -1,9 +1,10 @@
package markdown
import (
- "fmt"
"html/template"
"strings"
+
+ "git.anhgelus.world/anhgelus/small-web/dom"
)
type astQuote struct {
@@ -12,15 +13,18 @@ type astQuote struct {
}
func (a *astQuote) Eval(opt *Option) (template.HTML, *ParseError) {
- var quote template.HTML
+ var quoteContent template.HTML
for _, c := range a.quote {
ct, err := c.Eval(opt)
if err != nil {
return "", err
}
- quote += ct
+ quoteContent += ct
}
- quote = template.HTML(fmt.Sprintf("<blockquote>%s</blockquote>", trimSpace(quote)))
+ blockquote := dom.NewLiteralContentElement(
+ "blockquote",
+ template.HTML(strings.TrimSpace(string(quoteContent))),
+ )
var source template.HTML
for _, c := range a.source {
ct, err := c.Eval(opt)
@@ -30,10 +34,13 @@ func (a *astQuote) Eval(opt *Option) (template.HTML, *ParseError) {
source += ct
}
source = template.HTML(strings.TrimSpace(string(source)))
+ quote := dom.NewContentElement("div", make([]dom.Element, 0))
+ quote.ClassList().Add("quote")
+ quote.Contents = append(quote.Contents, blockquote)
if len(source) > 0 {
- return template.HTML(fmt.Sprintf(`<div class="quote">%s<p>%s</p></div>`, quote, source)), nil
+ quote.Contents = append(quote.Contents, dom.NewParagraph(source))
}
- return template.HTML(fmt.Sprintf(`<div class="quote">%s</div>`, quote)), nil
+ return quote.Render(), nil
}
func quote(lxs *lexers) (*astQuote, *ParseError) {