htmlbeautifier 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,21 +3,39 @@ require 'htmlbeautifier/parser'
3
3
  module HtmlBeautifier
4
4
  class HtmlParser < Parser
5
5
  ELEMENT_CONTENT = %r{ (?:[^<>]|<%.*?%>)* }mx
6
+ HTML_VOID_ELEMENTS = %r{(?:
7
+ area | base | br | col | command | embed | hr | img | input | keygen |
8
+ link | meta | param | source | track | wbr
9
+ )}mix
6
10
 
7
11
  def initialize
8
12
  super do |p|
9
- p.map %r{(<%-?=?)(.*?)(-?%>)}m, :embed
10
- p.map %r{<!--\[.*?\]>}m, :open_ie_cc
11
- p.map %r{<!\[.*?\]-->}m, :close_ie_cc
12
- p.map %r{<!--.*?-->}m, :standalone_element
13
- p.map %r{<!.*?>}m, :standalone_element
14
- p.map %r{(<script#{ELEMENT_CONTENT}>)(.*?)(</script>)}m, :foreign_block
15
- p.map %r{(<style#{ELEMENT_CONTENT}>)(.*?)(</style>)}m, :foreign_block
16
- p.map %r{<#{ELEMENT_CONTENT}/>}m, :standalone_element
17
- p.map %r{</#{ELEMENT_CONTENT}>}m, :close_element
18
- p.map %r{<#{ELEMENT_CONTENT}>}m, :open_element
19
- p.map %r{\s+}, :whitespace
20
- p.map %r{[^<]+}, :text
13
+ p.map %r{(<%-?=?)(.*?)(-?%>)}m,
14
+ :embed
15
+ p.map %r{<!--\[.*?\]>}m,
16
+ :open_ie_cc
17
+ p.map %r{<!\[.*?\]-->}m,
18
+ :close_ie_cc
19
+ p.map %r{<!--.*?-->}m,
20
+ :standalone_element
21
+ p.map %r{<!.*?>}m,
22
+ :standalone_element
23
+ p.map %r{(<script#{ELEMENT_CONTENT}>)(.*?)(</script>)}m,
24
+ :foreign_block
25
+ p.map %r{(<style#{ELEMENT_CONTENT}>)(.*?)(</style>)}m,
26
+ :foreign_block
27
+ p.map %r{<#{ELEMENT_CONTENT}/>}m,
28
+ :standalone_element
29
+ p.map %r{<#{HTML_VOID_ELEMENTS}#{ELEMENT_CONTENT}>}m,
30
+ :standalone_element
31
+ p.map %r{</#{ELEMENT_CONTENT}>}m,
32
+ :close_element
33
+ p.map %r{<#{ELEMENT_CONTENT}>}m,
34
+ :open_element
35
+ p.map %r{\s+},
36
+ :whitespace
37
+ p.map %r{[^<]+},
38
+ :text
21
39
  end
22
40
  end
23
41
  end
@@ -2,7 +2,7 @@ module HtmlBeautifier #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -60,16 +60,8 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
60
60
  end
61
61
 
62
62
  def test_should_remove_trailing_space_from_script_lines
63
- source = code(%q(
64
- <script>
65
- f();
66
- </script>
67
- ))
68
- expected = code(%q(
69
- <script>
70
- f();
71
- </script>
72
- ))
63
+ source = %Q(<script>\n f(); \n</script>)
64
+ expected = %Q(<script>\n f();\n</script>)
73
65
  assert_beautifies expected, source
74
66
  end
75
67
 
@@ -79,6 +71,23 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
79
71
  assert_beautifies expected, source
80
72
  end
81
73
 
74
+ def test_should_ignore_case_of_script
75
+ source = code(%q(
76
+ <SCRIPT>
77
+
78
+ // code
79
+
80
+ </SCRIPT>
81
+ ))
82
+ expected = code(%q(
83
+ <SCRIPT>
84
+ // code
85
+ </SCRIPT>
86
+ ))
87
+ assert_beautifies expected, source
88
+ end
89
+
90
+
82
91
  def test_should_indent_styles
83
92
  source = code(%q(
84
93
  <style>
@@ -118,15 +127,23 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
118
127
  end
119
128
 
120
129
  def test_should_remove_trailing_space_from_style_lines
130
+ source = %Q(<style>\n .foo{ margin: 0; } \n</style>)
131
+ expected = %Q(<style>\n .foo{ margin: 0; }\n</style>)
132
+ assert_beautifies expected, source
133
+ end
134
+
135
+ def test_should_ignore_case_of_style
121
136
  source = code(%q(
122
- <style>
123
- .foo{ margin: 0; }
124
- </style>
137
+ <STYLE>
138
+
139
+ .foo{ margin: 0; }
140
+
141
+ </STYLE>
125
142
  ))
126
143
  expected = code(%q(
127
- <style>
144
+ <STYLE>
128
145
  .foo{ margin: 0; }
129
- </style>
146
+ </STYLE>
130
147
  ))
131
148
  assert_beautifies expected, source
132
149
  end
@@ -248,4 +265,22 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
248
265
  assert_beautifies source, source
249
266
  end
250
267
 
268
+ def test_should_not_indent_html_void_elements
269
+ source = code(%q(
270
+ <meta>
271
+ <input id="id">
272
+ <br>
273
+ ))
274
+ assert_beautifies source, source
275
+ end
276
+
277
+ def test_should_ignore_case_of_void_elements
278
+ source = code(%q(
279
+ <META>
280
+ <INPUT id="id">
281
+ <BR>
282
+ ))
283
+ assert_beautifies source, source
284
+ end
285
+
251
286
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: htmlbeautifier
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul Battley
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2013-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :development
@@ -27,7 +27,7 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  none: false
30
- description:
30
+ description: A normaliser/beautifier for HTML that also understands embedded Ruby.
31
31
  email: pbattley@gmail.com
32
32
  executables:
33
33
  - htmlbeautifier
@@ -37,14 +37,14 @@ files:
37
37
  - Rakefile
38
38
  - README.md
39
39
  - bin/htmlbeautifier
40
- - test/test_html_beautifier_regression.rb
41
- - test/test_parser.rb
42
40
  - test/test_html_beautifier_integration.rb
43
41
  - test/test_helper.rb
44
- - lib/htmlbeautifier/html_parser.rb
42
+ - test/test_html_beautifier_regression.rb
43
+ - test/test_parser.rb
44
+ - lib/htmlbeautifier/version.rb
45
45
  - lib/htmlbeautifier/parser.rb
46
+ - lib/htmlbeautifier/html_parser.rb
46
47
  - lib/htmlbeautifier/beautifier.rb
47
- - lib/htmlbeautifier/version.rb
48
48
  - lib/htmlbeautifier/builder.rb
49
49
  - lib/htmlbeautifier.rb
50
50
  homepage: http://github.com/threedaymonk/htmlbeautifier
@@ -71,5 +71,5 @@ rubyforge_project:
71
71
  rubygems_version: 1.8.25
72
72
  signing_key:
73
73
  specification_version: 3
74
- summary: A normaliser/beautifier for HTML that also understands embedded Ruby.
74
+ summary: HTML/ERB beautifier
75
75
  test_files: []