diff --git a/html2text.go b/html2text.go
index 991109b..f79fbe3 100644
--- a/html2text.go
+++ b/html2text.go
@@ -24,7 +24,7 @@ var numericEntityRE = regexp.MustCompile(`(?i)^#(x?[a-f0-9]+)$`)
type options struct {
lbr string
linksInnerText bool
- listSupport bool
+ listPrefix string
}
func newOptions() *options {
@@ -52,13 +52,18 @@ func WithLinksInnerText() Option {
}
}
-// WithListSupport formats
and - lists with dashes
-func WithListSupport() Option {
+// WithListSupportPrefix formats
and - lists with the specified prefix
+func WithListSupportPrefix(prefix string) Option {
return func(o *options) {
- o.listSupport = true
+ o.listPrefix = prefix
}
}
+// WithListSupport formats
and - lists with " - " prefix
+func WithListSupport() Option {
+ return WithListSupportPrefix(" - ")
+}
+
func parseHTMLEntity(entName string) (string, bool) {
if r, ok := entity[entName]; ok {
return string(r), true
@@ -242,8 +247,8 @@ func HTML2TextWithOptions(html string, reqOpts ...Option) string {
if tagNameLowercase == "/ul" || tagNameLowercase == "/ol" {
outBuf.WriteString(opts.lbr)
} else if tagNameLowercase == "li" || tagNameLowercase == "li/" {
- if opts.listSupport {
- outBuf.WriteString(opts.lbr + "- ")
+ if opts.listPrefix != "" {
+ outBuf.WriteString(opts.lbr + opts.listPrefix)
} else {
outBuf.WriteString(opts.lbr)
}
diff --git a/html2text_test.go b/html2text_test.go
index a3fab9a..0aaeabb 100644
--- a/html2text_test.go
+++ b/html2text_test.go
@@ -128,8 +128,8 @@ func TestHTML2Text(t *testing.T) {
})
Convey("Optional list support", func() {
- So(HTML2TextWithOptions(`list of items`, WithListSupport()), ShouldEqual, "list of items\r\n- One\r\n- Two\r\n- Three\r\n")
- So(HTML2TextWithOptions(`list of items
- One
- Two
- Three
`, WithListSupport()), ShouldEqual, "list of items\r\n- One\r\n- Two\r\n- Three\r\n")
+ So(HTML2TextWithOptions(`list of items`, WithListSupport()), ShouldEqual, "list of items\r\n - One\r\n - Two\r\n - Three\r\n")
+ So(HTML2TextWithOptions(`list of items- One
- Two
- Three
`, WithListSupport()), ShouldEqual, "list of items\r\n - One\r\n - Two\r\n - Three\r\n")
})
Convey("Custom HTML Tags", func() {