From 02f1e42a7f83f041627eace65675c1d6cea7e8cc Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 1 Oct 2025 09:55:15 +0200 Subject: feat(markdown): trim space in top level --- mardown/ast.go | 5 +++++ mardown/ast_header.go | 2 +- mardown/ast_paragraph.go | 2 +- mardown/ast_quote.go | 3 +-- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'mardown') diff --git a/mardown/ast.go b/mardown/ast.go index 3a16903..55fd3b9 100644 --- a/mardown/ast.go +++ b/mardown/ast.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "html/template" + "strings" ) var ErrUnkownLexType = errors.New("unkown lex type") @@ -91,3 +92,7 @@ func getBlock(lxs *lexers, newLine bool) (block, error) { } return b, err } + +func trimSpace(s template.HTML) template.HTML { + return template.HTML(strings.TrimSpace(string(s))) +} diff --git a/mardown/ast_header.go b/mardown/ast_header.go index 64e47ad..5b13411 100644 --- a/mardown/ast_header.go +++ b/mardown/ast_header.go @@ -22,7 +22,7 @@ func (a *astHeader) Eval() (template.HTML, error) { if err != nil { return "", err } - return template.HTML(fmt.Sprintf("%s", a.level, content, a.level)), nil + return template.HTML(fmt.Sprintf("%s", a.level, trimSpace(content), a.level)), nil } func header(lxs *lexers) (*astHeader, error) { diff --git a/mardown/ast_paragraph.go b/mardown/ast_paragraph.go index 5961370..1a78ced 100644 --- a/mardown/ast_paragraph.go +++ b/mardown/ast_paragraph.go @@ -27,7 +27,7 @@ func (a *astParagraph) Eval() (template.HTML, error) { if a.oneLine { return content, nil } - return template.HTML(fmt.Sprintf("

%s

", content)), nil + return template.HTML(fmt.Sprintf("

%s

", trimSpace(content))), nil } func paragraph(lxs *lexers, oneLine bool) (*astParagraph, error) { diff --git a/mardown/ast_quote.go b/mardown/ast_quote.go index 101b854..5ed1208 100644 --- a/mardown/ast_quote.go +++ b/mardown/ast_quote.go @@ -20,8 +20,7 @@ func (a *astQuote) Eval() (template.HTML, error) { } quote += ct } - quote = template.HTML(strings.TrimSpace(string(quote))) - quote = template.HTML(fmt.Sprintf("
%s
", quote)) + quote = template.HTML(fmt.Sprintf("
%s
", trimSpace(quote))) var source template.HTML for _, c := range a.source { ct, err := c.Eval() -- cgit v1.2.3