aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_code.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-15 17:38:35 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-15 17:38:35 +0100
commit587f4ff7152dbf82b39f0d9afc61be7a16570686 (patch)
treeb715ead5e80e98af31d3a1bc3b2d15a5016936c7 /markdown/ast_code.go
parent3312977ebeff03edc5b1bc1a2f815cad6a1ba7b8 (diff)
fix(markdown): adding linebreak at the beginning in multiline code block
create tests for code
Diffstat (limited to 'markdown/ast_code.go')
-rw-r--r--markdown/ast_code.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/markdown/ast_code.go b/markdown/ast_code.go
index 6b949f2..4fa962a 100644
--- a/markdown/ast_code.go
+++ b/markdown/ast_code.go
@@ -42,28 +42,26 @@ func (a *astCode) Eval(_ *Option) (template.HTML, *ParseError) {
func code(lxs *lexers) (*astCode, *ParseError) {
tree := new(astCode)
- current := lxs.Current().Value
- if len(current) == 3 {
+ codeTag := lxs.Current().Value
+ if len(codeTag) == 3 {
tree.codeType = codeMultiLine
- } else if len(current) == 1 {
+ } else if len(codeTag) == 1 {
tree.codeType = codeOneLine
} else {
return nil, &ParseError{lxs: *lxs, internal: ErrInvalidCodeFormat}
}
started := false
- for lxs.Next() && lxs.Current().Value != current {
- if lxs.Current().Type == lexerBreak {
+ for lxs.Next() && lxs.Current().Value != codeTag {
+ isBreak := lxs.Current().Type == lexerBreak
+ if started || (tree.codeType == codeOneLine && !isBreak) {
+ tree.content += lxs.Current().Value
+ } else if !isBreak {
+ tree.before += lxs.Current().Value
+ } else {
if tree.codeType == codeOneLine {
return nil, &ParseError{lxs: *lxs, internal: ErrInvalidCodeFormat}
}
- if !started {
- started = true
- }
- }
- if started || tree.codeType == codeOneLine {
- tree.content += lxs.Current().Value
- } else {
- tree.before += lxs.Current().Value
+ started = true
}
}
return tree, nil