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('foo<!-- bar -->qux', {'break-around-comments': false}, function (html) {
|
24 | assert.equal(html, 'foo<!-- bar -->qux');
|
25 | });
|
26 |
|
27 | cleaner.clean('foo<!-- bar -->qux', {'break-around-comments': true}, function (html) {
|
28 | assert.equal(html, 'foo\n<!-- bar -->\nqux');
|
29 | });
|
30 |
|
31 |
|
32 | cleaner.clean('foo<div></div>bar', {'break-around-tags': []}, function (html) {
|
33 | assert.equal(html, 'foo<div></div>bar');
|
34 | });
|
35 |
|
36 | cleaner.clean('foo<div></div>bar', {'break-around-tags': ['div']}, function (html) {
|
37 | assert.equal(html, 'foo\n<div></div>\nbar');
|
38 | });
|
39 |
|
40 |
|
41 | cleaner.clean('<span color="red">foo</span>', {'remove-attributes': []}, function (html) {
|
42 | assert.equal(html, '<span color="red">foo</span>');
|
43 | });
|
44 |
|
45 | cleaner.clean('<span color="red">foo</span>', {'remove-attributes': ['color']}, function (html) {
|
46 | assert.equal(html, '<span>foo</span>');
|
47 | });
|
48 |
|
49 |
|
50 | cleaner.clean('<!-- foo -->', {'remove-comments': false}, function (html) {
|
51 | assert.equal(html, '<!-- foo -->');
|
52 | });
|
53 |
|
54 | cleaner.clean('<!-- foo -->', {'remove-comments': true}, function (html) {
|
55 | assert.equal(html, '');
|
56 | });
|
57 |
|
58 |
|
59 | cleaner.clean('<p></p>', {'remove-empty-tags': []}, function (html) {
|
60 | assert.equal(html, '<p></p>');
|
61 | });
|
62 |
|
63 | cleaner.clean('<p></p>', {'remove-empty-tags': ['p']}, function (html) {
|
64 | assert.equal(html, '');
|
65 | });
|
66 |
|
67 |
|
68 | cleaner.clean('<font face="arial">foo</font>', {'remove-tags': []}, function (html) {
|
69 | assert.equal(html, '<font face="arial">foo</font>');
|
70 | });
|
71 |
|
72 | cleaner.clean('<font face="arial">foo</font>', {'remove-tags': ['font']}, function (html) {
|
73 | assert.equal(html, 'foo');
|
74 | });
|
75 |
|
76 |
|
77 | cleaner.clean('Foo Bar', {'replace-nbsp': false}, function (html) {
|
78 | assert.equal(html, 'Foo Bar');
|
79 | });
|
80 |
|
81 | cleaner.clean('Foo Bar', {'replace-nbsp': true}, function (html) {
|
82 | assert.equal(html, 'Foo Bar');
|
83 | });
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | cleaner.clean('foo<span>bar</span>qux', {'indent': ' '}, function (html) {
|
92 | assert.equal(html, 'foo<span>bar</span>qux');
|
93 | });
|
94 |
|
95 | cleaner.clean('foo<span><!-- bar --></span>qux', {'break-around-comments': false, 'indent': ' '}, function (html) {
|
96 | assert.equal(html, 'foo<span><!-- bar --></span>qux');
|
97 | });
|
98 |
|
99 | cleaner.clean('foo<span><!-- bar --></span>qux', {'break-around-comments': true, 'indent': ' '}, function (html) {
|
100 | assert.equal(html, 'foo\n<span>\n <!-- bar -->\n</span>\nqux');
|
101 | });
|
102 |
|
103 | cleaner.clean('foo<span><span>bar</span></span>qux', {'indent': ' '}, function (html) {
|
104 | assert.equal(html, 'foo<span><span>bar</span></span>qux');
|
105 | });
|
106 |
|
107 | cleaner.clean('foo<span><div>bar</div></span>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
108 | assert.equal(html, 'foo\n<span>\n <div>bar</div>\n</span>\nqux');
|
109 | });
|
110 |
|
111 | cleaner.clean('foo<span><span><div>bar</div></span></span>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
112 | assert.equal(html, 'foo\n<span>\n <span>\n <div>bar</div>\n </span>\n</span>\nqux');
|
113 | });
|
114 |
|
115 |
|
116 |
|
117 | cleaner.clean('foo<div>bar</div>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
118 | assert.equal(html, 'foo\n<div>bar</div>\nqux');
|
119 | });
|
120 |
|
121 | cleaner.clean('foo<div><!-- bar --></div>qux', {'break-around-comments': false, 'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
122 | assert.equal(html, 'foo\n<div><!-- bar --></div>\nqux');
|
123 | });
|
124 |
|
125 | cleaner.clean('foo<div><!-- bar --></div>qux', {'break-around-comments': true, 'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
126 | assert.equal(html, 'foo\n<div>\n <!-- bar -->\n</div>\nqux');
|
127 | });
|
128 |
|
129 | cleaner.clean('foo<div><span>bar</span></div>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
130 | assert.equal(html, 'foo\n<div><span>bar</span></div>\nqux');
|
131 | });
|
132 |
|
133 | cleaner.clean('foo<div><div>bar</div></div>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
134 | assert.equal(html, 'foo\n<div>\n <div>bar</div>\n</div>\nqux');
|
135 | });
|
136 |
|
137 | cleaner.clean('foo<div><span><div>bar</div></span></div>qux', {'break-around-tags': ['div'], 'indent': ' '}, function (html) {
|
138 | assert.equal(html, 'foo\n<div>\n <span>\n <div>bar</div>\n </span>\n</div>\nqux');
|
139 | });
|
140 |
|
141 | console.log('all tests passed');
|