From 5ff5db6770a4cd7f506121287070fb342de62e79 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 21 Dec 2025 14:16:03 +0100 Subject: feat(markdown): option to render poem --- markdown/ast_paragraph.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'markdown/ast_paragraph.go') 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: -- cgit v1.2.3