aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_paragraph.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-21 14:16:03 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-21 14:16:03 +0100
commit5ff5db6770a4cd7f506121287070fb342de62e79 (patch)
tree2a244fe4a52170754f80c3cca1554a4c6c185e5e /markdown/ast_paragraph.go
parentb8b0189bab9e282624fcf64d622cf100f3ddec11 (diff)
feat(markdown): option to render poem
Diffstat (limited to 'markdown/ast_paragraph.go')
-rw-r--r--markdown/ast_paragraph.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/markdown/ast_paragraph.go b/markdown/ast_paragraph.go
index 70d3414..30fd4a1 100644
--- a/markdown/ast_paragraph.go
+++ b/markdown/ast_paragraph.go
@@ -34,6 +34,15 @@ func (a *astParagraph) Eval(opt *Option) (template.HTML, *ParseError) {
).Render(), nil
}
+type astBreak struct{}
+
+func (a astBreak) Eval(opt *Option) (template.HTML, *ParseError) {
+ if opt.Poem {
+ return dom.NewVoidElement("br").Render(), nil
+ }
+ return " ", nil
+}
+
func paragraph(lxs *lexers, oneLine bool) (*astParagraph, *ParseError) {
tree := new(astParagraph)
tree.oneLine = oneLine
@@ -46,11 +55,11 @@ func paragraph(lxs *lexers, oneLine bool) (*astParagraph, *ParseError) {
s := lxs.Current().Value
// replace line break by space
if n > 0 && len(tree.content) != 0 {
- s = " " + s
+ tree.content = append(tree.content, astBreak{})
}
tree.content = append(tree.content, conv(s))
}
- lxs.current-- // because we do not use it before the next
+ lxs.Before() // because we do not use it before the next
for lxs.Next() && n < maxBreak {
switch lxs.Current().Type {
case lexerBreak: