Skip to content

Commit a2eb234

Browse files
author
Mario Hros
committed
new line fix
1 parent 514e0f4 commit a2eb234

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

html2text.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ func HTMLEntitiesToText(htmlEntsText string) string {
5353

5454
for i, r := range htmlEntsText {
5555
switch {
56-
case r == '\n', r == '\r': // skip new lines
57-
continue
58-
5956
case r == ';' && inEnt:
6057
inEnt = false
6158
continue
@@ -117,6 +114,9 @@ func HTML2Text(html string) string {
117114
}
118115

119116
switch {
117+
case r <= 0xD, r == 0x85, r == 0x2028, r == 0x2029: // skip new lines
118+
continue
119+
120120
case r == ';' && inEnt: // end of html entity
121121
inEnt = false
122122
shouldOutput = true

html2text_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestHTML2Text(t *testing.T) {
2121
})
2222

2323
Convey("Line breaks", func() {
24+
So(HTML2Text("should \nignore \r\nnew lines"), ShouldEqual, "should ignore new lines")
2425
So(HTML2Text(`two<br>line<br/>breaks`), ShouldEqual, "two\r\nline\r\nbreaks")
2526
So(HTML2Text(`<p>two</p><p>paragraphs</p>`), ShouldEqual, "two\r\nparagraphs")
2627
})

0 commit comments

Comments
 (0)