author | Mikael Berthe <mikael@lilotux.net> |
Sat, 13 May 2017 12:36:38 +0200 | |
changeset 132 | 4bf4f6ce268e |
parent 126 | 7d712d2bde73 |
permissions | -rw-r--r-- |
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
1 |
package html2text |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 |
import ( |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
4 |
"github.com/stretchr/testify/assert" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 |
"testing" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 |
) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
8 |
func TestTextify(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
9 |
expected := "body\nbody2" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
r, e := Textify("<html><body><b>body</b><br/>body2</body></html>") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
11 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
14 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 |
func TestTextifyDiv(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
16 |
expected := "first\nsecond" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 |
r, e := Textify("<div>first</div>second") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
18 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
22 |
/* |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 |
func TestTextifyLink(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
expected := "somelink (link: someurl)" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
r, e := Textify("<a href=\"someurl\">somelink</a>") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
28 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
*/ |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
30 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
31 |
func TestTextifyDontDuplicateLink(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 |
expected := "www.awesome.com" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
r, e := Textify("<a href=\"www.awesome.com\">www.awesome.com</a>") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
34 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
35 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
36 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
37 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
38 |
func TestTextifySpaces(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 |
expected := "hello" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
40 |
r, e := Textify("<div> hello </div>") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
41 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
42 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
45 |
/* I don't think we want that for Mastodon... |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
46 |
func TestTextifySpacesMultiple(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
47 |
expected := "hello goodbye" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
48 |
r, e := Textify("<span> hello </span><span> goodbye </span>") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
49 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
51 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
52 |
*/ |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
53 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
54 |
func TestTextifyNonBreakingSpace(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
55 |
expected := "a a" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
56 |
r, e := Textify("a a") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
57 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
58 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
59 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
60 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
61 |
func TestTextifyLimitedNewLines(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
62 |
expected := "abc\nxyz" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
63 |
r, e := Textify("abc <br/> <br/> <br/> <br/>xyz") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
64 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
65 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
66 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
67 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
68 |
func TestTextifyTable(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
69 |
expected := `Join by phone |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
70 |
1-877-668-4490 Call-in toll-free number (US/Canada) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
71 |
1-408-792-6300 Call-in toll number (US/Canada) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
72 |
Access code: 111 111 111 |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
73 |
https://akqa.webex.com/akqa/globalcallin.php?serviceType=MC&ED=299778282&tollFree=1 | http://www.webex.com/pdf/tollfree_restrictions.pdf` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
74 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
75 |
test := `<table width="747" style="width:448.2pt;"> <col width="747" style="width:448.2pt;"> <tbody> <tr> <td><font face="Arial" color="#666666"><b>Join by phone</b></font></td> </tr> <tr> <td><font face="Arial" size="3" color="#666666"><span style="font-size:11.5pt;"><b>1-877-668-4490</b> Call-in toll-free number (US/Canada)</span></font></td> </tr> <tr> <td><font face="Arial" size="3" color="#666666"><span style="font-size:11.5pt;"><b>1-408-792-6300</b> Call-in toll number (US/Canada)</span></font></td> </tr> <tr> <td><font face="Arial" size="3" color="#666666"><span style="font-size:11.5pt;">Access code: 111 111 111</span></font></td> </tr> <tr> <td><a href="https://akqa.webex.com/akqa/globalcallin.php?serviceType=MC&ED=299778282&tollFree=1"><font face="Arial" size="2" color="#00AFF9"><span style="font-size:10pt;"><u>Global call-in numbers</u></span></font></a><font face="Arial" size="3" color="#666666"><span style="font-size:11.5pt;"> | </span></font><a href="http://www.webex.com/pdf/tollfree_restrictions.pdf"><font face="Arial" size="2" color="#00AFF9"><span style="font-size:10pt;"><u>Toll-free calling restrictions</u></span></font></a></td> </tr> </tbody> </table>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
76 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
77 |
r, e := Textify(test) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
78 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
79 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
80 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
81 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
82 |
func TestTextifyComment(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
83 |
expected := "this should appear" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
84 |
r, e := Textify("<!-- this should not appear -->this should appear") |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
85 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
86 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
87 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
88 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
89 |
func TestTextifyCommentInHead(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
90 |
expected := "qwerty" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
91 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
92 |
body := `<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="Generator" content="Microsoft Exchange Server"> <!-- converted from rtf --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style> </head> <body>qwerty</body> </html>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
93 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
94 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
95 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
96 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
97 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
98 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
99 |
func TestTextifyLists(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
100 |
expected := "a\nb\n1\n2" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
101 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
102 |
body := `<ol><li>a</li><li>b</li></ol><ul><li>1</li><li>2</li></ul>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
103 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
104 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
105 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
106 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
107 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
108 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
109 |
func TestTextifyMastodonSample1(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
110 |
expected := "@magi hello \\U0001F607 @TEST" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
111 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
112 |
body := `<p><span class=\"h-card\"><a href=\"https://example.com/@magi\">@<span>magi</span></a></span> hello \U0001F607 <span class=\"h-card\"><a href=\"https://example.com/@TEST\">@<span>TEST</span></a></span></p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
113 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
114 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
115 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
116 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
117 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
118 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
119 |
func TestTextifyMastodonSample2(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
120 |
expected := "@cadey It looks good at first glance\n\"case <-stop\" Actually you don't listen to stop channel, you close it if you want to stop the listener." |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
121 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
122 |
body := `<p><span class="h-card"><a href="https://www.example.com/@cadey" class="u-url mention">@<span>cadey</span></a></span> It looks good at first glance</p><p>"case <-stop" Actually you don't listen to stop channel, you close it if you want to stop the listener.</p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
123 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
124 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
125 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
126 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
127 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
128 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
129 |
func TestTextifyMastodonSample3(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
130 |
expected := "From timeline: Materials research creates potential for improved computer chips and transistors #phys #physics ..." |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
131 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
132 |
body := `From timeline: Materials research creates potential for improved computer chips and transistors #<span class="tag"><a href="https://social.oalm.gub.uy/tag/phys">phys</a></span> #<span class="tag"><a href="https://social.oalm.gub.uy/tag/physics">physics</a></span><p>...</p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
133 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
134 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
135 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
136 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
137 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
138 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
139 |
func TestTextifyMastodonSample4(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
140 |
expected := "Vous reprendrez bien un peu de #Tolkein ?\n#Arte +7 propose un ensemble de 6 vidéos en plus du documentaire:\nhttp://www.arte.tv/fr/videos/RC-014610/tolkien/" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
141 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
142 |
body := `<p>Vous reprendrez bien un peu de <a href="https://framapiaf.org/tags/tolkein">#<span>Tolkein</span></a> ?<br><a href="https://framapiaf.org/tags/arte">#<span>Arte</span></a>+7 propose un ensemble de 6 vidéos en plus du documentaire:</p><p><a href="http://www.arte.tv/fr/videos/RC-014610/tolkien/"><span class="invisible">http://www.</span><span class="ellipsis">arte.tv/fr/videos/RC-014610/to</span><span class="invisible">lkien/</span></a></p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
143 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
144 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
145 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
146 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
147 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
148 |
|
132
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
149 |
func TestTextifyMastodonMention(t *testing.T) { |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
150 |
expected := "La tête à @Toto \\o/" |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
151 |
|
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
152 |
body := `<p>La tête à <span class="h-card"><a href="https://example.com/@Toto">@<span>Toto</span></a></span> \o/</p>` |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
153 |
|
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
154 |
r, e := Textify(body) |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
155 |
assert.Nil(t, e) |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
156 |
assert.Equal(t, expected, r) |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
157 |
} |
4bf4f6ce268e
html2text: Try and handle one more mention case
Mikael Berthe <mikael@lilotux.net>
parents:
126
diff
changeset
|
158 |
|
126
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
159 |
func TestTextifyMastodonMentionAndTag(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
160 |
expected := "@ACh Mais heu ! Moi aussi je fais du #TootRadio de gens morts il y a 5 siècles. Gesulado, Charpentier, Mireille Mathieu..." |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
161 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
162 |
body := `<p><span class="h-card"><a href="https://mamot.fr/@ACh">@<span>ACh</span></a></span> Mais heu ! Moi aussi je fais du <a href="https://example.com/tags/tootradio">#<span>TootRadio</span></a> de gens morts il y a 5 siècles. Gesulado, Charpentier, Mireille Mathieu...</p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
163 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
164 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
165 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
166 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
167 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
168 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
169 |
func TestTextifyMastodonLinkSpacing(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
170 |
expected := "\"Twitter\" https://twitter.com/holly/status/123456789012345678" |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
171 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
172 |
body := `<p>"Twitter" <a href="https://twitter.com/holly/status/123456789012345678"><span class="invisible">https://</span><span class="ellipsis">twitter.com/holly/status/86266</span><span class="invisible">1234567890123</span></a></p>` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
173 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
174 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
175 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
176 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
177 |
} |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
178 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
179 |
func TestTextifyMastodonMentionGNUSocial(t *testing.T) { |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
180 |
expected := "@username Hello." |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
181 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
182 |
body := `@<a href="https://example.com/user/12345">username</a> Hello.` |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
183 |
|
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
184 |
r, e := Textify(body) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
185 |
assert.Nil(t, e) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
186 |
assert.Equal(t, expected, r) |
7d712d2bde73
Much improved html2text (fromhtml)
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
187 |
} |