diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-01 09:55:15 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-01 09:55:15 +0200 |
| commit | 02f1e42a7f83f041627eace65675c1d6cea7e8cc (patch) | |
| tree | 34b01105e6ffa49916d9c6882411fb1590630cc2 /mardown | |
| parent | 11e4c0d5e62f5a7f3840a83081567eff33f16fd3 (diff) | |
feat(markdown): trim space in top level
Diffstat (limited to 'mardown')
| -rw-r--r-- | mardown/ast.go | 5 | ||||
| -rw-r--r-- | mardown/ast_header.go | 2 | ||||
| -rw-r--r-- | mardown/ast_paragraph.go | 2 | ||||
| -rw-r--r-- | mardown/ast_quote.go | 3 |
4 files changed, 8 insertions, 4 deletions
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("<h%d>%s</h%d>", a.level, content, a.level)), nil + return template.HTML(fmt.Sprintf("<h%d>%s</h%d>", 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("<p>%s</p>", content)), nil + return template.HTML(fmt.Sprintf("<p>%s</p>", 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("<blockquote>%s</blockquote>", quote)) + quote = template.HTML(fmt.Sprintf("<blockquote>%s</blockquote>", trimSpace(quote))) var source template.HTML for _, c := range a.source { ct, err := c.Eval() |
