Skip to content
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,33 @@ func File(numLines int, fileName string, code []byte) map[int]string {
}

htmlw.Flush()
finalNewLine := false
if len(code) > 0 {
finalNewLine = code[len(code)-1] == '\n'
}

m := make(map[int]string, numLines)
for k, v := range strings.SplitN(htmlbuf.String(), "\n", numLines) {
line := k + 1
content := string(v)
log.Info("%s", content)

//need to keep lines that are only \n so copy/paste works properly in browser
if content == "" {
content = "\n"
} else if content == `</span><span class="w">` {
content += "\n"
}
m[line] = content
}
if finalNewLine {
m[numLines+1] = "<span class=\"w\">\n</span>"
}

for i, line := range m {
log.Info("%d: %q", i, line)
}

return m
}

Expand Down