Skip to content

Commit 90bb105

Browse files
author
William Griffiths
committed
Add new line for unordered lists
1 parent a2eb234 commit 90bb105

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

html2text.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ func HTML2Text(html string) string {
160160
shouldOutput = true
161161
tagName := strings.ToLower(html[tagStart:i])
162162

163-
if tagName == "br" || tagName == "br/" {
163+
if tagName == "/ul" {
164+
outBuf.WriteString("\r\n")
165+
} else if tagName == "li" || tagName == "li/" {
166+
outBuf.WriteString("\r\n")
167+
} else if tagName == "br" || tagName == "br/" {
164168
// new line
165169
outBuf.WriteString("\r\n")
166170
} else if tagName == "p" || tagName == "/p" {

html2text_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package html2text
22

3-
import "testing"
4-
import . "github.com/smartystreets/goconvey/convey"
3+
import (
4+
"testing"
5+
6+
. "github.com/smartystreets/goconvey/convey"
7+
)
58

69
func TestHTML2Text(t *testing.T) {
710
Convey("HTML2Text should work", t, func() {
@@ -34,6 +37,7 @@ func TestHTML2Text(t *testing.T) {
3437
ShouldEqual, "would you pay in ¢, £, ¥ or €?")
3538
So(HTML2Text(`Tom & Jerry is not an entity`), ShouldEqual, "Tom & Jerry is not an entity")
3639
So(HTML2Text(`this &neither; as you see`), ShouldEqual, "this &neither; as you see")
40+
So(HTML2Text(`list of items<ul><li>One</li><li>Two</li><li>Three</li></ul>`), ShouldEqual, "list of items\r\nOne\r\nTwo\r\nThree\r\n")
3741
})
3842

3943
Convey("Full HTML structure", func() {

0 commit comments

Comments
 (0)