Skip to content

Commit a9ab4df

Browse files
kkeybbsMario Hros
authored andcommitted
Fix tag pattern to support custom html tags
1 parent 52104c9 commit a9ab4df

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

html2text.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
)
1414

1515
var lbr = WIN_LBR
16-
var badTagnamesRE = regexp.MustCompile(`^(head|script|style|a)($|\s*)`)
16+
var badTagnamesRE = regexp.MustCompile(`^(head|script|style|a)($|\s+)`)
1717
var linkTagRE = regexp.MustCompile(`a.*href=('([^']*?)'|"([^"]*?)")`)
1818
var badLinkHrefRE = regexp.MustCompile(`javascript:`)
1919
var headersRE = regexp.MustCompile(`^(\/)?h[1-6]`)

html2text_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,11 @@ func TestHTML2Text(t *testing.T) {
8787
So(HTML2Text(`<p>two</p><p>paragraphs</p>`), ShouldEqual, "two\r\n\r\nparagraphs")
8888
})
8989

90+
Convey("Custom HTML Tags", func() {
91+
So(HTML2Text(`<aa>hello</aa>`), ShouldEqual, "hello")
92+
So(HTML2Text(`<aa >hello</aa>`), ShouldEqual, "hello")
93+
So(HTML2Text(`<aa x="1">hello</aa>`), ShouldEqual, "hello")
94+
})
95+
9096
})
9197
}

0 commit comments

Comments
 (0)