htmlbeautifier 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/htmlbeautifier/builder.rb +6 -1
- data/lib/htmlbeautifier/html_parser.rb +5 -7
- data/lib/htmlbeautifier/version.rb +1 -1
- data/test/test_executable.rb +66 -0
- data/test/test_html_beautifier_regression.rb +21 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aaf76d4d6d04d9e89603730cb13417bf03a0321
|
4
|
+
data.tar.gz: 56808b31dc24878165d2bd3c55cf43b93fd893de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0168d0c22faff926c2af24939434dea45fb35b5b95451efd207819f7401aedc32dec9a00a9bbda8a7e423be2e49af6ce3d0296a844ee69bb34593c18cc777080
|
7
|
+
data.tar.gz: 90c25b3b9628e98a4edddfc7069ce610d31570cfafe97ce6d2586683dbfdc633c7f12afc3bc7290966fc1dcee86c8499d3277f2c6a88dc8b43f19b9872f42f9f
|
@@ -17,6 +17,7 @@ module HtmlBeautifier
|
|
17
17
|
@new_line = false
|
18
18
|
@tab = ' ' * tab_stops
|
19
19
|
@output = output
|
20
|
+
@empty = true
|
20
21
|
@ie_cc_levels = []
|
21
22
|
end
|
22
23
|
|
@@ -30,11 +31,12 @@ module HtmlBeautifier
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def emit(s)
|
33
|
-
if @new_line && !@
|
34
|
+
if @new_line && !@empty
|
34
35
|
@output << ("\n" + @tab * @level)
|
35
36
|
end
|
36
37
|
@output << s
|
37
38
|
@new_line = false
|
39
|
+
@empty = false
|
38
40
|
end
|
39
41
|
|
40
42
|
def new_line(*_args)
|
@@ -70,13 +72,16 @@ module HtmlBeautifier
|
|
70
72
|
end
|
71
73
|
|
72
74
|
def preformatted_block(opening, content, closing)
|
75
|
+
new_line
|
73
76
|
emit opening
|
74
77
|
emit content
|
75
78
|
emit closing
|
79
|
+
new_line
|
76
80
|
end
|
77
81
|
|
78
82
|
def standalone_element(e)
|
79
83
|
emit e
|
84
|
+
new_line if e =~ /^<br[^\w]/
|
80
85
|
end
|
81
86
|
|
82
87
|
def close_block_element(e)
|
@@ -8,10 +8,10 @@ module HtmlBeautifier
|
|
8
8
|
link | meta | param | source | track | wbr
|
9
9
|
)}mix
|
10
10
|
HTML_BLOCK_ELEMENTS = %r{(?:
|
11
|
-
address |
|
12
|
-
|
13
|
-
|
14
|
-
thead | tr | ul
|
11
|
+
address | article | aside | audio | blockquote | canvas | dd | dir | div |
|
12
|
+
dl | dt | fieldset | figcaption | figure | footer | form | h1 | h2 | h3 |
|
13
|
+
h4 | h5 | h6 | header | hr | li | menu | noframes | noscript | ol | p |
|
14
|
+
pre | section | table | tbody | td | tfoot | th | thead | tr | ul | video
|
15
15
|
)}mix
|
16
16
|
|
17
17
|
def initialize
|
@@ -32,9 +32,7 @@ module HtmlBeautifier
|
|
32
32
|
:foreign_block
|
33
33
|
p.map %r{(<pre#{ELEMENT_CONTENT}>)(.*?)(</pre>)}mi,
|
34
34
|
:preformatted_block
|
35
|
-
p.map %r{<#{ELEMENT_CONTENT}
|
36
|
-
:standalone_element
|
37
|
-
p.map %r{<#{HTML_VOID_ELEMENTS}(?: #{ELEMENT_CONTENT})?>}m,
|
35
|
+
p.map %r{<#{HTML_VOID_ELEMENTS}(?: #{ELEMENT_CONTENT})?/?>}m,
|
38
36
|
:standalone_element
|
39
37
|
p.map %r{</#{HTML_BLOCK_ELEMENTS}>}m,
|
40
38
|
:close_block_element
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class TestExecutable < Test::Unit::TestCase
|
6
|
+
def path_to(*partial)
|
7
|
+
File.join(File.expand_path('../..', __FILE__), *partial)
|
8
|
+
end
|
9
|
+
|
10
|
+
def command
|
11
|
+
'ruby -I%s %s' % [
|
12
|
+
escape(path_to('lib')),
|
13
|
+
escape(path_to('bin', 'htmlbeautifier'))
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def escape(s)
|
18
|
+
Shellwords.escape(s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_beautify_a_file_in_place
|
22
|
+
FileUtils.mkdir_p path_to('tmp')
|
23
|
+
input = "<p>\nfoo\n</p>"
|
24
|
+
expected = "<p>\n foo\n</p>\n"
|
25
|
+
path = path_to('tmp', 'in-place.html')
|
26
|
+
File.open(path, 'w') do |f|
|
27
|
+
f.write input
|
28
|
+
end
|
29
|
+
|
30
|
+
system '%s %s' % [command, escape(path)]
|
31
|
+
|
32
|
+
output = File.read(path)
|
33
|
+
assert_equal expected, output
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_beautify_a_file_from_stdin_to_stdout
|
37
|
+
FileUtils.mkdir_p path_to('tmp')
|
38
|
+
input = "<p>\nfoo\n</p>"
|
39
|
+
expected = "<p>\n foo\n</p>\n"
|
40
|
+
in_path = path_to('tmp', 'input.html')
|
41
|
+
out_path = path_to('tmp', 'output.html')
|
42
|
+
File.open(in_path, 'w') do |f|
|
43
|
+
f.write input
|
44
|
+
end
|
45
|
+
|
46
|
+
system '%s < %s > %s' % [command, escape(in_path), escape(out_path)]
|
47
|
+
|
48
|
+
output = File.read(out_path)
|
49
|
+
assert_equal expected, output
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_allow_configurable_number_of_tab_stops
|
53
|
+
FileUtils.mkdir_p path_to('tmp')
|
54
|
+
input = "<p>\nfoo\n</p>"
|
55
|
+
expected = "<p>\n foo\n</p>\n"
|
56
|
+
path = path_to('tmp', 'in-place.html')
|
57
|
+
File.open(path, 'w') do |f|
|
58
|
+
f.write input
|
59
|
+
end
|
60
|
+
|
61
|
+
system '%s --tab-stops=3 %s' % [command, escape(path)]
|
62
|
+
|
63
|
+
output = File.read(path)
|
64
|
+
assert_equal expected, output
|
65
|
+
end
|
66
|
+
end
|
@@ -321,4 +321,25 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
|
|
321
321
|
))
|
322
322
|
assert_beautifies expected, source
|
323
323
|
end
|
324
|
+
|
325
|
+
def test_should_add_newlines_around_pre_element
|
326
|
+
source = %(<section><pre>puts "Allons-y!"</pre></section>)
|
327
|
+
expected = code(%(
|
328
|
+
<section>
|
329
|
+
<pre>puts "Allons-y!"</pre>
|
330
|
+
</section>
|
331
|
+
))
|
332
|
+
assert_beautifies expected, source
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_should_add_newline_after_br_element
|
336
|
+
source = %(<p>Lorem ipsum<br>dolor sit<br />amet,<br/>consectetur.</p>)
|
337
|
+
expected = code(%(
|
338
|
+
<p>Lorem ipsum<br>
|
339
|
+
dolor sit<br />
|
340
|
+
amet,<br/>
|
341
|
+
consectetur.</p>
|
342
|
+
))
|
343
|
+
assert_beautifies expected, source
|
344
|
+
end
|
324
345
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlbeautifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Battley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/htmlbeautifier/html_parser.rb
|
41
41
|
- lib/htmlbeautifier/parser.rb
|
42
42
|
- lib/htmlbeautifier/version.rb
|
43
|
+
- test/test_executable.rb
|
43
44
|
- test/test_helper.rb
|
44
45
|
- test/test_html_beautifier_integration.rb
|
45
46
|
- test/test_html_beautifier_regression.rb
|