Skip to content

Commit

Permalink
Fix tag pattern to support custom html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kkeybbs authored and Mario Hros committed Nov 19, 2020
1 parent 52104c9 commit a9ab4df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion html2text.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
)

var lbr = WIN_LBR
var badTagnamesRE = regexp.MustCompile(`^(head|script|style|a)($|\s*)`)
var badTagnamesRE = regexp.MustCompile(`^(head|script|style|a)($|\s+)`)
var linkTagRE = regexp.MustCompile(`a.*href=('([^']*?)'|"([^"]*?)")`)
var badLinkHrefRE = regexp.MustCompile(`javascript:`)
var headersRE = regexp.MustCompile(`^(\/)?h[1-6]`)
Expand Down
6 changes: 6 additions & 0 deletions html2text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@ func TestHTML2Text(t *testing.T) {
So(HTML2Text(`<p>two</p><p>paragraphs</p>`), ShouldEqual, "two\r\n\r\nparagraphs")
})

Convey("Custom HTML Tags", func() {
So(HTML2Text(`<aa>hello</aa>`), ShouldEqual, "hello")
So(HTML2Text(`<aa >hello</aa>`), ShouldEqual, "hello")
So(HTML2Text(`<aa x="1">hello</aa>`), ShouldEqual, "hello")
})

})
}

0 comments on commit a9ab4df

Please sign in to comment.