From f5607e75f98d50dfd0496cfd5a76bc0d905403f7 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 30 Sep 2025 20:23:51 +0200 Subject: refactor(markdown): use paragraph for header --- mardown/ast_paragraph.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'mardown/ast_paragraph.go') diff --git a/mardown/ast_paragraph.go b/mardown/ast_paragraph.go index 3ebc519..04f2086 100644 --- a/mardown/ast_paragraph.go +++ b/mardown/ast_paragraph.go @@ -2,6 +2,7 @@ package mardown import ( "errors" + "fmt" "html/template" ) @@ -12,6 +13,7 @@ var ( type astParagraph struct { content []block + oneLine bool } func (a *astParagraph) Eval() (template.HTML, error) { @@ -23,18 +25,26 @@ func (a *astParagraph) Eval() (template.HTML, error) { } content += ct } - return content, nil + if a.oneLine { + return content, nil + } + return template.HTML(fmt.Sprintf("

%s

", content)), nil } -func paragraph(lxs lexers) (block, error) { +func paragraph(lxs lexers, oneLine bool) (*astParagraph, error) { tree := new(astParagraph) + tree.oneLine = oneLine + maxBreak := 2 + if oneLine { + maxBreak = 1 + } n := 0 lxs.current-- // because we do not use it before the next - for lxs.Next() && n < 2 { + for lxs.Next() && n < maxBreak { switch lxs.Current().Type { case lexerBreak: n++ - case lexerLiteral: + case lexerLiteral, lexerHeader: tree.content = append(tree.content, astLiteral(lxs.Current().Value)) case lexerModifier: //TODO: handle -- cgit v1.2.3