forked from uznam8x/html-formatter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
80 lines (64 loc) · 2.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Testing. */
import { closify } from './src/closify'
import { entify } from './src/entify'
import { minify } from './src/minify'
import { prettify } from './src/prettify'
const uhtml = `<form id="3" > <!--
This is a comment. --><!-- This is a second comment. --><label for="email-0">
What's your email?</label><input id="email-0" type="email"
title="We need your email for verification." name="email" required><!-- This is another comment. -->
<label for="1">What fruits do you like?</label><fieldset id="1">
<input id="fruits-1-0" type="checkbox" name="fruits" value="apples">
<label for="fruits-1-0" >Apples< /label><br><div><!-- This is an embedded comment. --></div>
<input id="fruits-1-1" type="checkbox" name="fruits" value="grapes">
<label for="fruits-1-1">Grapes</label><br></fieldset>
<textarea >
Did you know that 3 > 2?
This is another paragraph.
</textarea><textarea class=" more stuff "> </textarea>
<br>
</form>`
const ehtml = `<textarea >
Did you know that 3 > 2?
This is another paragraph.
</textarea><textarea class=" more stuff "> </textarea>`
const phtml = `<form id="3">
<!-- This is a comment. -->
<!-- This is a second comment. -->
<label for="email-0">What's your email?</label>
<input id="email-0" type="email" title="We need your email for verification." name="email" required />
<!-- This is another comment. -->
<label for="1">What fruits do you like?</label>
<fieldset id="1">
<input id="fruits-1-0" type="checkbox" name="fruits" value="apples" />
<label for="fruits-1-0">Apples</label>
<br />
<div>
<!-- This is an embedded comment. -->
</div>
<input id="fruits-1-1" type="checkbox" name="fruits" value="grapes" />
<label for="fruits-1-1">Grapes</label>
<br />
</fieldset>
<textarea>Did you know that 3 > 2? This is another paragraph.</textarea>
<textarea class="more stuff"></textarea>
<br>
</form>`
const chtml = `<form id="3">
<!-- This is a comment. -->
<!-- This is a second comment. --><br><input><br><input></form>`
const prettified_html = prettify(uhtml)
const entified_html = entify(ehtml, true)
const minified_html = minify(phtml)
const closified_html = closify(chtml)
const plain_text = prettify('This should boomerang as-is.')
console.log('All pretty:')
console.log(prettified_html, '\n')
console.log('With entities:')
console.log(entified_html, '\n')
console.log('All minified:')
console.log(minified_html, '\n')
console.log('With self-closing:')
console.log(closified_html, '\n')
console.log('Plain text:')
console.log(plain_text)