@@ -12,14 +12,25 @@ func TestHTML2Text(t *testing.T) {
1212 Convey ("Links" , func () {
1313 So (HTML2Text (`<div></div>` ), ShouldEqual , "" )
1414 So (HTML2Text (`<div>simple text</div>` ), ShouldEqual , "simple text" )
15- So (HTML2Text (`click <a href="test">here</a>` ), ShouldEqual , "click here <test>" )
16- So (HTML2Text (`click <a class="x" href="test">here</a>` ), ShouldEqual , "click here <test>" )
17- So (HTML2Text (`click <a href="ents/'x'">here</a>` ), ShouldEqual , "click here <ents/'x'>" )
18- So (HTML2Text (`click <a href="javascript:void(0)">here</a>` ), ShouldEqual , "click here" )
19- So (HTML2Text (`click <a href="test"><span>here</span> or here</a>` ), ShouldEqual , "click here or here <test>" )
20- So (HTML2Text (`click <a href="http://bit.ly/2n4wXRs">news</a>` ), ShouldEqual , "click news <http://bit.ly/2n4wXRs>" )
21- So (HTML2Text (`<a rel="mw:WikiLink" href="/wiki/yet#English" title="yet">yet</a>, <a rel="mw:WikiLink" href="/wiki/not_yet#English" title="not yet">not yet</a>` ), ShouldEqual , "yet </wiki/yet#English>, not yet </wiki/not_yet#English>" )
22- So (HTML2Text (`click <a href="one">here<a href="two"> or</a><span> here</span></a>` ), ShouldEqual , "click here or <one> here <two>" )
15+
16+ // the original behavior
17+ So (HTML2Text (`click <a href="test">here</a>` ), ShouldEqual , "click test" )
18+ So (HTML2Text (`click <a class="x" href="test">here</a>` ), ShouldEqual , "click test" )
19+ So (HTML2Text (`click <a href="ents/'x'">here</a>` ), ShouldEqual , "click ents/'x'" )
20+ So (HTML2Text (`click <a href="javascript:void(0)">here</a>` ), ShouldEqual , "click " )
21+ So (HTML2Text (`click <a href="test"><span>here</span> or here</a>` ), ShouldEqual , "click test" )
22+ So (HTML2Text (`click <a href="http://bit.ly/2n4wXRs">news</a>` ), ShouldEqual , "click http://bit.ly/2n4wXRs" )
23+ So (HTML2Text (`<a rel="mw:WikiLink" href="/wiki/yet#English" title="yet">yet</a>, <a rel="mw:WikiLink" href="/wiki/not_yet#English" title="not yet">not yet</a>` ), ShouldEqual , "/wiki/yet#English, /wiki/not_yet#English" )
24+
25+ // with inner text
26+ So (HTML2TextWithOptions (`click <a href="test">here</a>` , WithLinksInnerText ()), ShouldEqual , "click here <test>" )
27+ So (HTML2TextWithOptions (`click <a class="x" href="test">here</a>` , WithLinksInnerText ()), ShouldEqual , "click here <test>" )
28+ So (HTML2TextWithOptions (`click <a href="ents/'x'">here</a>` , WithLinksInnerText ()), ShouldEqual , "click here <ents/'x'>" )
29+ So (HTML2TextWithOptions (`click <a href="javascript:void(0)">here</a>` , WithLinksInnerText ()), ShouldEqual , "click here" )
30+ So (HTML2TextWithOptions (`click <a href="test"><span>here</span> or here</a>` , WithLinksInnerText ()), ShouldEqual , "click here or here <test>" )
31+ So (HTML2TextWithOptions (`click <a href="http://bit.ly/2n4wXRs">news</a>` , WithLinksInnerText ()), ShouldEqual , "click news <http://bit.ly/2n4wXRs>" )
32+ So (HTML2TextWithOptions (`<a rel="mw:WikiLink" href="/wiki/yet#English" title="yet">yet</a>, <a rel="mw:WikiLink" href="/wiki/not_yet#English" title="not yet">not yet</a>` , WithLinksInnerText ()), ShouldEqual , "yet </wiki/yet#English>, not yet </wiki/not_yet#English>" )
33+ So (HTML2TextWithOptions (`click <a href="one">here<a href="two"> or</a><span> here</span></a>` , WithLinksInnerText ()), ShouldEqual , "click here or <one> here <two>" )
2334 })
2435
2536 Convey ("Inlines" , func () {
@@ -80,7 +91,7 @@ func TestHTML2Text(t *testing.T) {
8091 ShouldEqual , "we are not interested in scripts" )
8192 })
8293
83- Convey ("Switching Unix and Windows line breaks" , func () {
94+ Convey ("Switching Unix and Windows line breaks (original behavior) " , func () {
8495 SetUnixLbr (true )
8596 So (HTML2Text (`two<br>line<br/>breaks` ), ShouldEqual , "two\n line\n breaks" )
8697 So (HTML2Text (`<p>two</p><p>paragraphs</p>` ), ShouldEqual , "two\n \n paragraphs" )
@@ -89,6 +100,13 @@ func TestHTML2Text(t *testing.T) {
89100 So (HTML2Text (`<p>two</p><p>paragraphs</p>` ), ShouldEqual , "two\r \n \r \n paragraphs" )
90101 })
91102
103+ Convey ("Switching Unix and Windows line breaks (new options)" , func () {
104+ So (HTML2TextWithOptions (`two<br>line<br/>breaks` , WithUnixLineBreaks ()), ShouldEqual , "two\n line\n breaks" )
105+ So (HTML2TextWithOptions (`<p>two</p><p>paragraphs</p>` , WithUnixLineBreaks ()), ShouldEqual , "two\n \n paragraphs" )
106+ So (HTML2TextWithOptions (`two<br>line<br/>breaks` ), ShouldEqual , "two\r \n line\r \n breaks" )
107+ So (HTML2TextWithOptions (`<p>two</p><p>paragraphs</p>` ), ShouldEqual , "two\r \n \r \n paragraphs" )
108+ })
109+
92110 Convey ("Custom HTML Tags" , func () {
93111 So (HTML2Text (`<aa>hello</aa>` ), ShouldEqual , "hello" )
94112 So (HTML2Text (`<aa >hello</aa>` ), ShouldEqual , "hello" )
0 commit comments