1 | var assert = require('assert'),
|
2 | cleaner = require('./index.js');
|
3 |
|
4 |
|
5 | cleaner.clean('Foo Bar', function (html) {
|
6 | assert.equal(html, 'Foo Bar');
|
7 | });
|
8 |
|
9 |
|
10 | cleaner.clean('Foo Bar', function (html) {
|
11 | assert.equal(html, 'Foo Bar');
|
12 | });
|
13 | cleaner.clean('Foo\nBar', function (html) {
|
14 | assert.equal(html, 'Foo Bar');
|
15 | });
|
16 |
|
17 |
|
18 | cleaner.clean(' foo\n', function (html) {
|
19 | assert.equal(html, 'foo');
|
20 | });
|
21 |
|
22 |
|
23 | cleaner.clean('<!DOCTYPE html>', function (html) {
|
24 | assert.equal(html, '<!DOCTYPE html>')
|
25 | });
|
26 |
|
27 |
|
28 | cleaner.clean('<A HREF="http://foo">bar</A>', function (html) {
|
29 | assert.equal(html, '<a href="http://foo">bar</a>');
|
30 | });
|
31 |
|
32 |
|
33 | cleaner.clean('<script type="text/javascript">console.log("foo");</script>', function (html) {
|
34 | assert.equal(html, '<script type="text/javascript">console.log("foo");</script>')
|
35 | });
|
36 |
|
37 |
|
38 | cleaner.clean('<style>a { color: red; }</style>', function (html) {
|
39 | assert.equal(html, '<style>a { color: red; }</style>')
|
40 | });
|
41 |
|
42 |
|
43 | cleaner.clean('foo<!-- bar -->qux', {'break-around-comments': false}, function (html) {
|
44 | assert.equal(html, 'foo<!-- bar -->qux');
|
45 | });
|
46 |
|
47 | cleaner.clean('foo<!-- bar -->qux', {'break-around-comments': true}, function (html) {
|
48 | assert.equal(html, 'foo\n<!-- bar -->\nqux');
|
49 | });
|
50 |
|
51 |
|
52 | cleaner.clean('foo<div></div>bar', {'break-around-tags': []}, function (html) {
|
53 | assert.equal(html, 'foo<div></div>bar');
|
54 | });
|
55 |
|
56 | cleaner.clean('foo<div></div>bar', {'break-around-tags': ['div']}, function (html) {
|
57 | assert.equal(html, 'foo\n<div></div>\nbar');
|
58 | });
|
59 |
|
60 |
|
61 | cleaner.clean('<span color="red">foo</span>', {'remove-attributes': []}, function (html) {
|
62 | assert.equal(html, '<span color="red">foo</span>');
|
63 | });
|
64 |
|
65 | cleaner.clean('<span color="red">foo</span>', {'remove-attributes': ['color']}, function (html) {
|
66 | assert.equal(html, '<span>foo</span>');
|
67 | });
|
68 |
|
69 |
|
70 | cleaner.clean('<!-- foo -->', {'remove-comments': false}, function (html) {
|
71 | assert.equal(html, '<!-- foo -->');
|
72 | });
|
73 |
|
74 | cleaner.clean('<!-- foo -->', {'remove-comments': true}, function (html) {
|
75 | assert.equal(html, '');
|
76 | });
|
77 |
|
78 |
|
79 | cleaner.clean('<p></p>', {'remove-empty-tags': []}, function (html) {
|
80 | assert.equal(html, '<p></p>');
|
81 | });
|
82 |
|
83 | cleaner.clean('<p></p>', {'remove-empty-tags': ['p']}, function (html) {
|
84 | assert.equal(html, '');
|
85 | });
|
86 |
|
87 |
|
88 | cleaner.clean('<font face="arial">foo</font>', {'remove-tags': []}, function (html) {
|
89 | assert.equal(html, '<font face="arial">foo</font>');
|
90 | });
|
91 |
|
92 | cleaner.clean('<font face="arial">foo</font>', {'remove-tags': ['font']}, function (html) {
|
93 | assert.equal(html, 'foo');
|
94 | });
|
95 |
|
96 |
|
97 | cleaner.clean('Foo Bar', {'replace-nbsp': false}, function (html) {
|
98 | assert.equal(html, 'Foo Bar');
|
99 | });
|
100 |
|
101 | cleaner.clean('Foo Bar', {'replace-nbsp': true}, function (html) {
|
102 | assert.equal(html, 'Foo Bar');
|
103 | });
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | cleaner.clean('foo<span>bar</span>qux', {'indent': ' '}, function (html) {
|
109 | assert.equal(html, 'foo<span>bar</span>qux');
|
110 | });
|
111 |
|
112 | cleaner.clean('foo<span><!-- bar --></span>qux', {'break-around-comments': false, 'indent': ' '}, function (html) {
|
113 | assert.equal(html, 'foo<span><!-- bar --></span>qux');
|
114 | });
|
115 |
|
116 | cleaner.clean('foo<span><!-- bar --></span>qux', {'break-around-comments': true, 'indent': ' '}, function (html) {
|
117 | assert.equal(html, 'foo\n<span>\n <!-- bar -->\n</span>\nqux');
|
118 | });
|
119 |
|
120 | cleaner.clean('foo<span><span>bar</span></span>qux', {'indent': ' '}, function (html) {
|
121 | assert.equal(html, 'foo<span><span>bar</span></span>qux');
|
122 | });
|
123 |
|
124 | cleaner.clean('foo<span><div>bar</div></span>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
125 | assert.equal(html, 'foo\n<span>\n <div>bar</div>\n</span>\nqux');
|
126 | });
|
127 |
|
128 | cleaner.clean('foo<span><span><div>bar</div></span></span>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
129 | assert.equal(html, 'foo\n<span>\n <span>\n <div>bar</div>\n </span>\n</span>\nqux');
|
130 | });
|
131 |
|
132 |
|
133 | var input = `<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
134 | <tr>
|
135 | <td height="31"><b>Currently we have these articles available:</b>
|
136 |
|
137 | <blockquote>
|
138 | <p><a href="foo.html">The History of Foo</a><br />
|
139 | An <span color="red">informative</span> piece of <font face="arial">information</font>.</p>
|
140 | <p><A HREF="bar.html">A Horse Walked Into a Bar</A><br/> The bartender said
|
141 | "Why the long face?"</p>
|
142 | </blockquote>
|
143 | </td>
|
144 | </tr>
|
145 | </table>`;
|
146 | var expected = `<table>
|
147 | <tr>
|
148 | <td>
|
149 | <b>Currently we have these articles available:</b>
|
150 | <blockquote>
|
151 | <p>
|
152 | <a href="foo.html">The History of Foo</a>
|
153 | <br>
|
154 | An <span>informative</span> piece of information.
|
155 | </p>
|
156 | <p>
|
157 | <a href="bar.html">A Horse Walked Into a Bar</a>
|
158 | <br>
|
159 | The bartender said "Why the long face?"
|
160 | </p>
|
161 | </blockquote>
|
162 | </td>
|
163 | </tr>
|
164 | </table>`;
|
165 | cleaner.clean(input, function (actual) {
|
166 | assert.equal(expected, actual);
|
167 | });
|
168 |
|
169 | console.log('all tests passed');
|