htmlbeautifier 1.4.2 → 1.4.3
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/README.md +4 -4
- data/bin/htmlbeautifier +3 -3
- data/lib/htmlbeautifier/builder.rb +1 -1
- data/lib/htmlbeautifier/html_parser.rb +17 -17
- data/lib/htmlbeautifier/parser.rb +2 -2
- data/lib/htmlbeautifier/ruby_indenter.rb +2 -2
- data/lib/htmlbeautifier/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd8d466ff4ebc3419c99968d8a82f617c9911c520a4623d649d72a821dcec5c
|
4
|
+
data.tar.gz: 28113c3062ebfcf3dd6cb5d30dfd551d658b6d3061e7127bfb50e5584266266c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c07ed38537750b35280e3131c9333f5c31deabff6da46f5a333557b8af5c261babda15f98a45f9ea9d8213f14368ad9b671fac38f61e7f7439a3d0edb2bb675
|
7
|
+
data.tar.gz: 76c39b1d92accd12e3b6c354b2214e0da149d7e400d0e66583b6505c498eadd8de79336abfcf90087d1ca9e56c00d6a0ec4b4f211da5924a7546fc65e1d84971
|
data/README.md
CHANGED
@@ -23,13 +23,13 @@ Ideal for tidying up Rails templates.
|
|
23
23
|
To update files in-place:
|
24
24
|
|
25
25
|
``` sh
|
26
|
-
$ htmlbeautifier file1 [file2 ...]
|
26
|
+
$ htmlbeautifier file1.html.erb [file2.html.erb ...]
|
27
27
|
```
|
28
28
|
|
29
29
|
or to operate on standard input and output:
|
30
30
|
|
31
31
|
``` sh
|
32
|
-
$ htmlbeautifier <
|
32
|
+
$ htmlbeautifier < untidy.html.erb > formatted.html.erb
|
33
33
|
```
|
34
34
|
|
35
35
|
### In your code
|
@@ -37,13 +37,13 @@ $ htmlbeautifier < input > output
|
|
37
37
|
```ruby
|
38
38
|
require 'htmlbeautifier'
|
39
39
|
|
40
|
-
beautiful = HtmlBeautifier.beautify(
|
40
|
+
beautiful = HtmlBeautifier.beautify(untify_html_string)
|
41
41
|
```
|
42
42
|
|
43
43
|
You can also specify how to indent (the default is two spaces):
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
beautiful = HtmlBeautifier.beautify(
|
46
|
+
beautiful = HtmlBeautifier.beautify(untidy_html_string, indent: "\t")
|
47
47
|
```
|
48
48
|
|
49
49
|
## Installation
|
data/bin/htmlbeautifier
CHANGED
@@ -8,13 +8,13 @@ require "stringio"
|
|
8
8
|
|
9
9
|
def beautify(name, input, output, options)
|
10
10
|
output.puts HtmlBeautifier.beautify(input, options)
|
11
|
-
rescue
|
11
|
+
rescue => e
|
12
12
|
raise "Error parsing #{name}: #{e}"
|
13
13
|
end
|
14
14
|
|
15
15
|
executable = File.basename(__FILE__)
|
16
16
|
|
17
|
-
options = {
|
17
|
+
options = {indent: " "}
|
18
18
|
parser = OptionParser.new do |opts|
|
19
19
|
opts.banner = "Usage: #{executable} [options] [file ...]"
|
20
20
|
opts.separator <<~STRING
|
@@ -101,7 +101,7 @@ if ARGV.any?
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
unless failures.empty?
|
104
|
-
|
104
|
+
warn [
|
105
105
|
"Lint failed - files would be modified:",
|
106
106
|
*failures
|
107
107
|
].join("\n")
|
@@ -19,39 +19,39 @@ module HtmlBeautifier
|
|
19
19
|
|
20
20
|
MAPPINGS = [
|
21
21
|
[%r{(<%-?=?)(.*?)(-?%>)}om,
|
22
|
-
|
22
|
+
:embed],
|
23
23
|
[%r{<!--\[.*?\]>}om,
|
24
|
-
|
24
|
+
:open_ie_cc],
|
25
25
|
[%r{<!\[.*?\]-->}om,
|
26
|
-
|
26
|
+
:close_ie_cc],
|
27
27
|
[%r{<!--.*?-->}om,
|
28
|
-
|
28
|
+
:standalone_element],
|
29
29
|
[%r{<!.*?>}om,
|
30
|
-
|
30
|
+
:standalone_element],
|
31
31
|
[%r{(<script#{ELEMENT_CONTENT}>)(.*?)(</script>)}omi,
|
32
|
-
|
32
|
+
:foreign_block],
|
33
33
|
[%r{(<style#{ELEMENT_CONTENT}>)(.*?)(</style>)}omi,
|
34
|
-
|
34
|
+
:foreign_block],
|
35
35
|
[%r{(<pre#{ELEMENT_CONTENT}>)(.*?)(</pre>)}omi,
|
36
|
-
|
36
|
+
:preformatted_block],
|
37
37
|
[%r{(<textarea#{ELEMENT_CONTENT}>)(.*?)(</textarea>)}omi,
|
38
|
-
|
38
|
+
:preformatted_block],
|
39
39
|
[%r{<#{HTML_VOID_ELEMENTS}(?: #{ELEMENT_CONTENT})?/?>}om,
|
40
|
-
|
40
|
+
:standalone_element],
|
41
41
|
[%r{</#{HTML_BLOCK_ELEMENTS}>}om,
|
42
|
-
|
42
|
+
:close_block_element],
|
43
43
|
[%r{<#{HTML_BLOCK_ELEMENTS}(?: #{ELEMENT_CONTENT})?>}om,
|
44
|
-
|
44
|
+
:open_block_element],
|
45
45
|
[%r{</#{ELEMENT_CONTENT}>}om,
|
46
|
-
|
46
|
+
:close_element],
|
47
47
|
[%r{<#{ELEMENT_CONTENT}[^/]>}om,
|
48
|
-
|
48
|
+
:open_element],
|
49
49
|
[%r{<[\w\-]+(?: #{ELEMENT_CONTENT})?/>}om,
|
50
|
-
|
50
|
+
:standalone_element],
|
51
51
|
[%r{(\s*\r?\n\s*)+}om,
|
52
|
-
|
52
|
+
:new_lines],
|
53
53
|
[%r{[^<\n]+},
|
54
|
-
|
54
|
+
:text]
|
55
55
|
].freeze
|
56
56
|
|
57
57
|
def initialize
|
@@ -26,14 +26,14 @@ module HtmlBeautifier
|
|
26
26
|
[source_so_far.chomp.split(%r{\n}).count, 1].max
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
private
|
30
30
|
|
31
31
|
def dispatch(receiver)
|
32
32
|
_, method = @maps.find { |pattern, _| @scanner.scan(pattern) }
|
33
33
|
raise "Unmatched sequence" unless method
|
34
34
|
|
35
35
|
receiver.__send__(method, *extract_params(@scanner))
|
36
|
-
rescue
|
36
|
+
rescue => e
|
37
37
|
raise "#{e.message} on line #{source_line_number}"
|
38
38
|
end
|
39
39
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module HtmlBeautifier
|
4
4
|
class RubyIndenter
|
5
|
-
INDENT_KEYWORDS = %w[if elsif else unless while until begin for].freeze
|
6
|
-
OUTDENT_KEYWORDS = %w[elsif else end].freeze
|
5
|
+
INDENT_KEYWORDS = %w[if elsif else unless while until begin for case when].freeze
|
6
|
+
OUTDENT_KEYWORDS = %w[elsif else end when].freeze
|
7
7
|
RUBY_INDENT = %r{
|
8
8
|
^ ( #{INDENT_KEYWORDS.join("|")} )\b
|
9
9
|
| \b ( do | \{ ) ( \s* \| [^|]+ \| )? $
|
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: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Battley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: standard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1'
|
47
|
+
version: '1.33'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1'
|
54
|
+
version: '1.33'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.4.15
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: HTML/ERB beautifier
|