htmlbeautifier 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/htmlbeautifier +11 -6
- data/lib/htmlbeautifier/builder.rb +13 -0
- data/lib/htmlbeautifier/html_parser.rb +2 -2
- data/lib/htmlbeautifier/version.rb +1 -1
- data/test/test_html_beautifier_regression.rb +30 -0
- metadata +28 -11
data/bin/htmlbeautifier
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'htmlbeautifier'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
|
-
def beautify(input, output)
|
5
|
+
def beautify(name, input, output)
|
5
6
|
HtmlBeautifier::Beautifier.new(output).scan(input)
|
6
7
|
output << "\n"
|
8
|
+
rescue => e
|
9
|
+
raise "Error parsing #{name}: #{e}"
|
7
10
|
end
|
8
11
|
|
9
12
|
if ARGV.any?
|
10
|
-
ARGV.each do |
|
11
|
-
input = File.read(
|
12
|
-
|
13
|
-
|
13
|
+
ARGV.each do |path|
|
14
|
+
input = File.read(path)
|
15
|
+
temppath = path + ".tmp"
|
16
|
+
File.open(temppath, "w") do |output|
|
17
|
+
beautify path, input, output
|
14
18
|
end
|
19
|
+
FileUtils.mv temppath, path
|
15
20
|
end
|
16
21
|
else
|
17
|
-
beautify $stdin.read, $stdout
|
22
|
+
beautify "standard input", $stdin.read, $stdout
|
18
23
|
end
|
@@ -17,6 +17,7 @@ module HtmlBeautifier
|
|
17
17
|
@new_line = true
|
18
18
|
@tab = ' ' * tab_stops
|
19
19
|
@output = output
|
20
|
+
@ie_cc_levels = []
|
20
21
|
end
|
21
22
|
|
22
23
|
def indent
|
@@ -83,6 +84,18 @@ module HtmlBeautifier
|
|
83
84
|
indent
|
84
85
|
end
|
85
86
|
|
87
|
+
def close_ie_cc(e)
|
88
|
+
raise "Unclosed conditional comment" if @ie_cc_levels.empty?
|
89
|
+
@level = @ie_cc_levels.pop
|
90
|
+
emit e
|
91
|
+
end
|
92
|
+
|
93
|
+
def open_ie_cc(e)
|
94
|
+
emit e
|
95
|
+
@ie_cc_levels.push @level
|
96
|
+
indent
|
97
|
+
end
|
98
|
+
|
86
99
|
def text(t)
|
87
100
|
emit(t.strip)
|
88
101
|
whitespace if t =~ /\s$/
|
@@ -7,8 +7,8 @@ module HtmlBeautifier
|
|
7
7
|
def initialize
|
8
8
|
super do |p|
|
9
9
|
p.map %r{(<%-?=?)(.*?)(-?%>)}m, :embed
|
10
|
-
p.map %r{<!--\[.*?\]>}m, :
|
11
|
-
p.map %r{<!\[.*?\]-->}m, :
|
10
|
+
p.map %r{<!--\[.*?\]>}m, :open_ie_cc
|
11
|
+
p.map %r{<!\[.*?\]-->}m, :close_ie_cc
|
12
12
|
p.map %r{<!--.*?-->}m, :standalone_element
|
13
13
|
p.map %r{<!.*?>}m, :standalone_element
|
14
14
|
p.map %r{(<script#{ELEMENT_CONTENT}>)(.*?)(</script>)}m, :foreign_block
|
@@ -218,4 +218,34 @@ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
|
|
218
218
|
assert_beautifies expected, source
|
219
219
|
end
|
220
220
|
|
221
|
+
def test_should_not_indent_comments
|
222
|
+
source = code(%q(
|
223
|
+
<!-- This is a comment -->
|
224
|
+
<!-- So is this -->
|
225
|
+
))
|
226
|
+
assert_beautifies source, source
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_should_not_indent_conditional_comments
|
230
|
+
source = code(%q(
|
231
|
+
<!--[if lt IE 7]><html lang="en-us" class="ie6"><![endif]-->
|
232
|
+
<!--[if IE 7]><html lang="en-us" class="ie7"><![endif]-->
|
233
|
+
<!--[if IE 8]><html lang="en-us" class="ie8"><![endif]-->
|
234
|
+
<!--[if gt IE 8]><!--><html lang="en-us"><!--<![endif]-->
|
235
|
+
<body>
|
236
|
+
</body>
|
237
|
+
</html>
|
238
|
+
))
|
239
|
+
assert_beautifies source, source
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_should_not_indent_doctype
|
243
|
+
source = code(%q(
|
244
|
+
<!DOCTYPE html>
|
245
|
+
<html>
|
246
|
+
</html>
|
247
|
+
))
|
248
|
+
assert_beautifies source, source
|
249
|
+
end
|
250
|
+
|
221
251
|
end
|
metadata
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlbeautifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paul Battley
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :development
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
prerelease: false
|
23
|
+
name: rake
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
none: false
|
14
30
|
description:
|
15
31
|
email: pbattley@gmail.com
|
16
32
|
executables:
|
@@ -21,37 +37,38 @@ files:
|
|
21
37
|
- Rakefile
|
22
38
|
- README.md
|
23
39
|
- bin/htmlbeautifier
|
40
|
+
- test/test_html_beautifier_regression.rb
|
41
|
+
- test/test_parser.rb
|
24
42
|
- test/test_html_beautifier_integration.rb
|
25
43
|
- test/test_helper.rb
|
26
|
-
- test/test_parser.rb
|
27
|
-
- test/test_html_beautifier_regression.rb
|
28
44
|
- lib/htmlbeautifier/html_parser.rb
|
29
|
-
- lib/htmlbeautifier/
|
45
|
+
- lib/htmlbeautifier/parser.rb
|
30
46
|
- lib/htmlbeautifier/beautifier.rb
|
31
47
|
- lib/htmlbeautifier/version.rb
|
32
|
-
- lib/htmlbeautifier/
|
48
|
+
- lib/htmlbeautifier/builder.rb
|
33
49
|
- lib/htmlbeautifier.rb
|
34
50
|
homepage: http://github.com/threedaymonk/htmlbeautifier
|
35
|
-
licenses:
|
51
|
+
licenses:
|
52
|
+
- MIT
|
36
53
|
post_install_message:
|
37
54
|
rdoc_options: []
|
38
55
|
require_paths:
|
39
56
|
- lib
|
40
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
58
|
requirements:
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
46
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
62
|
none: false
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
64
|
requirements:
|
49
65
|
- - ! '>='
|
50
66
|
- !ruby/object:Gem::Version
|
51
67
|
version: '0'
|
68
|
+
none: false
|
52
69
|
requirements: []
|
53
70
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.25
|
55
72
|
signing_key:
|
56
73
|
specification_version: 3
|
57
74
|
summary: A normaliser/beautifier for HTML that also understands embedded Ruby.
|