Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions html2text.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type options struct {
func newOptions() *options {
// apply defaults
return &options{
lbr: WIN_LBR,
lbr: WIN_LBR,
keepSpaces: false,
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func HTML2TextWithOptions(html string, reqOpts ...Option) string {

if tagNameLowercase == "/ul" || tagNameLowercase == "/ol" {
outBuf.WriteString(opts.lbr)
} else if tagNameLowercase == "li" || tagNameLowercase == "li/" {
} else if tagNameLowercase == "li" || tagNameLowercase == "li/" || strings.HasPrefix(tagNameLowercase, "li ") {
if opts.listPrefix != "" {
outBuf.WriteString(opts.lbr + opts.listPrefix)
} else {
Expand Down
5 changes: 5 additions & 0 deletions html2text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func TestHTML2Text(t *testing.T) {
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")
})

Convey("List with classes", func() {
So(HTML2Text(`list of items<ul><li class="menu-item">One</li><li class="menu-item">Two</li><li class="menu-item">Three</li></ul>`), ShouldEqual, "list of items\r\nOne\r\nTwo\r\nThree\r\n")
So(HTML2Text(`list of items<ol><li class="menu-item">One</li><li class="menu-item">Two</li><li class="menu-item">Three</li></ol>`), ShouldEqual, "list of items\r\nOne\r\nTwo\r\nThree\r\n")
})

Convey("Optional list support", func() {
So(HTML2TextWithOptions(`list of items<ul><li>One</li><li>Two</li><li>Three</li></ul>`, WithListSupport()), ShouldEqual, "list of items\r\n - One\r\n - Two\r\n - Three\r\n")
So(HTML2TextWithOptions(`list of items<ol><li>One</li><li>Two</li><li>Three</li></ol>`, WithListSupport()), ShouldEqual, "list of items\r\n - One\r\n - Two\r\n - Three\r\n")
Expand Down