Merge pull request #387 from n-peugnet/mangled-lines
Fix mangled newlines in some code blocks
This commit is contained in:
commit
99a5c7caed
@ -305,27 +305,21 @@ func (parser *htmlParser) syntaxHighlight(text, language string) Entity {
|
|||||||
|
|
||||||
var children []Entity
|
var children []Entity
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
if token.Value == "\n" {
|
lines := strings.SplitAfter(token.Value, "\n")
|
||||||
children = append(children, NewBreakEntity())
|
for _, line := range lines {
|
||||||
|
line_len := len(line)
|
||||||
|
if line_len == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t := token.Clone()
|
||||||
|
|
||||||
} else if token.Type.String() == "CommentSingle" {
|
if line[line_len-1:] == "\n" {
|
||||||
children = append(children, tokenToTextEntity(style, &token))
|
t.Value = line[:line_len-1]
|
||||||
children = append(children, NewBreakEntity())
|
children = append(children, tokenToTextEntity(style, &t), NewBreakEntity())
|
||||||
|
} else {
|
||||||
} else if token.Type.String() == "CommentMultiline" {
|
|
||||||
lines := strings.Split(token.Value, "\n")
|
|
||||||
for i, line := range lines {
|
|
||||||
t := token.Clone()
|
|
||||||
t.Value = line
|
t.Value = line
|
||||||
children = append(children, tokenToTextEntity(style, &t))
|
children = append(children, tokenToTextEntity(style, &t))
|
||||||
|
|
||||||
if i < len(lines)-1 {
|
|
||||||
children = append(children, NewBreakEntity())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
children = append(children, tokenToTextEntity(style, &token))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user