Skip to content

Commit

Permalink
remove newLineInHTML = "
"
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jul 28, 2022
1 parent c8107f8 commit 025e3d9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
12 changes: 0 additions & 12 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ import (
// don't index files larger than this many bytes for performance purposes
const sizeLimit = 1024 * 1024

// newLineInHTML is the HTML entity to be used for newline in HTML content, if it's empty then the original "\n" is kept
// this option is here for 2 purposes:
// (1) make it easier to switch back to the original "\n" if there is any compatibility issue in the future
// (2) make it clear to do tests: "
" is the real newline for rendering, '\n' is ignorable/trim-able and could be ignored
var newLineInHTML = "
"

var (
// For custom user mapping
highlightMapping = map[string]string{}
Expand Down Expand Up @@ -200,9 +194,6 @@ func File(fileName, language string, code []byte) ([]string, error) {
for i := 1; i < len(lines); i++ {
line := lines[i]
line = strings.TrimSuffix(line, "</span></span>")
if newLineInHTML != "" && line != "" && line[len(line)-1] == '\n' {
line = line[:len(line)-1] + newLineInHTML
}
m = append(m, line)
}
return m, nil
Expand All @@ -222,9 +213,6 @@ func PlainText(code []byte) []string {
break
}
s := gohtml.EscapeString(content)
if newLineInHTML != "" && s != "" && s[len(s)-1] == '\n' {
s = s[:len(s)-1] + newLineInHTML
}
m = append(m, s)
}
return m
Expand Down
21 changes: 0 additions & 21 deletions modules/highlight/highlight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ func lines(s string) []string {
}

func TestFile(t *testing.T) {
defaultNewLineInHTML := newLineInHTML
defer func() {
newLineInHTML = defaultNewLineInHTML
}()

newLineInHTML = "&#10;"
tests := []struct {
name string
code string
Expand Down Expand Up @@ -93,20 +87,9 @@ c=2
assert.EqualValues(t, expected, actual)
})
}

newLineInHTML = ""
out, err := File("test-original-newline.py", "", []byte("a=1\n"))
assert.NoError(t, err)
assert.EqualValues(t, `<span class="n">a</span><span class="o">=</span><span class="mi">1</span>`+"\n", strings.Join(out, ""))
}

func TestPlainText(t *testing.T) {
defaultNewLineInHTML := newLineInHTML
defer func() {
newLineInHTML = defaultNewLineInHTML
}()

newLineInHTML = "&#10;"
tests := []struct {
name string
code string
Expand Down Expand Up @@ -170,8 +153,4 @@ c=2`),
assert.EqualValues(t, expected, actual)
})
}

newLineInHTML = ""
out := PlainText([]byte("a=1\n"))
assert.EqualValues(t, "a=1\n", strings.Join(out, ""))
}

0 comments on commit 025e3d9

Please sign in to comment.