Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mangled newlines in some code blocks #387

Merged
merged 2 commits into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions ui/messages/html/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,21 @@ func (parser *htmlParser) syntaxHighlight(text, language string) Entity {

var children []Entity
for _, token := range tokens {
if token.Value == "\n" {
children = append(children, NewBreakEntity())

} else if token.Type.String() == "CommentSingle" {
children = append(children, tokenToTextEntity(style, &token))
children = append(children, NewBreakEntity())
lines := strings.SplitAfter(token.Value, "\n")
for _, line := range lines {
line_len := len(line)
if line_len == 0 {
continue
}
t := token.Clone()

} else if token.Type.String() == "CommentMultiline" {
lines := strings.Split(token.Value, "\n")
for i, line := range lines {
t := token.Clone()
if line[line_len-1:] == "\n" {
t.Value = line[:line_len-1]
children = append(children, tokenToTextEntity(style, &t), NewBreakEntity())
} else {
t.Value = line
children = append(children, tokenToTextEntity(style, &t))

if i < len(lines)-1 {
children = append(children, NewBreakEntity())
}
}

} else {
children = append(children, tokenToTextEntity(style, &token))
}
}

Expand Down