htmlbeautifier 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 657518afa5b160297e6b490855c02526f48ad144
4
- data.tar.gz: bfdfbca49d50e276f2314a893ecc0b70b6392115
3
+ metadata.gz: 818d22d7f95ad8d6e04cd9873ac17c76b45e214a
4
+ data.tar.gz: 5969729a1fd18825c7ee8769570b06091afa9d1f
5
5
  SHA512:
6
- metadata.gz: 9a96bc60da54b69d972b80d5faf47a547dc7ab403e19c4ab6685dce4896a71a76bf9b7f49ce3b2c8039d8f0b661fe5c9b21c740116ac49e7e49313a11bd0a903
7
- data.tar.gz: cfe7bb9dceaad5997e65ba6fdc397a0ce5a30ee3012e295c1a1fdc2dedcf3a34661d662b92c83ec28ea4d675f99c82a05c7a2924f8f3f13d32f12db094d82fb8
6
+ metadata.gz: b58be67dccb5256cd6f0d9de0eab7be4e6d3654de867167859faa9d15d0e7721aeebd32b0fba89b6e81c5817b0d632536a8d6d32f6bb51568709b86c11636d29
7
+ data.tar.gz: a8e35db53495bf2b95bb11c6b605d17b3afbff46f321b7a35d3e2c1825b736cebddc15134c7e9930b1fb63dacb9807311c9c02cc049c5fc5896a29a96dfb16c4
@@ -50,6 +50,12 @@ END
50
50
  ) do |num|
51
51
  options[:stop_on_errors] = num
52
52
  end
53
+ opts.on(
54
+ "-b", "--keep-blank-lines NUMBER", Integer,
55
+ "Set number of consecutive blank lines"
56
+ ) do |num|
57
+ options[:keep_blank_lines] = num
58
+ end
53
59
  opts.on(
54
60
  "-h", "--help",
55
61
  "Display this help message and exit"
@@ -15,6 +15,8 @@ module HtmlBeautifier
15
15
  # is false, i.e. continue to process the rest of the document.
16
16
  # initial_level - The entire output will be indented by this number of steps.
17
17
  # Default is 0.
18
+ # keep_blank_lines - an integer for the number of consecutive empty lines
19
+ # to keep in output.
18
20
  #
19
21
  def self.beautify(html, options = {})
20
22
  if options[:tab_stops]
@@ -6,7 +6,8 @@ module HtmlBeautifier
6
6
  DEFAULT_OPTIONS = {
7
7
  indent: " ",
8
8
  initial_level: 0,
9
- stop_on_errors: false
9
+ stop_on_errors: false,
10
+ keep_blank_lines: 0
10
11
  }
11
12
 
12
13
  def initialize(output, options = {})
@@ -14,6 +15,7 @@ module HtmlBeautifier
14
15
  @tab = options[:indent]
15
16
  @stop_on_errors = options[:stop_on_errors]
16
17
  @level = options[:initial_level]
18
+ @keep_blank_lines = options[:keep_blank_lines]
17
19
  @new_line = false
18
20
  @empty = true
19
21
  @ie_cc_levels = []
@@ -45,7 +47,7 @@ module HtmlBeautifier
45
47
  @empty = false
46
48
  end
47
49
 
48
- def new_line(*)
50
+ def new_line
49
51
  @new_line = true
50
52
  end
51
53
 
@@ -121,9 +123,15 @@ module HtmlBeautifier
121
123
  indent
122
124
  end
123
125
 
126
+ def new_lines(*content)
127
+ blank_lines = content.first.scan(%r{\n}).count - 1
128
+ blank_lines = [blank_lines, @keep_blank_lines].min
129
+ @output << "\n" * blank_lines
130
+ new_line
131
+ end
132
+
124
133
  def text(t)
125
- emit t.chomp
126
- new_line if t.end_with?("\n")
134
+ emit t
127
135
  end
128
136
  end
129
137
  end
@@ -45,9 +45,9 @@ module HtmlBeautifier
45
45
  :close_element],
46
46
  [%r{<#{ELEMENT_CONTENT}>}om,
47
47
  :open_element],
48
- [%r{\s*\r?\n\s*}om,
49
- :new_line],
50
- [%r{[^<]+},
48
+ [%r{(\s*\r?\n\s*)+}om,
49
+ :new_lines],
50
+ [%r{[^<\n]+},
51
51
  :text]]
52
52
 
53
53
  def initialize
@@ -1,8 +1,8 @@
1
1
  module HtmlBeautifier #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 2
5
- TINY = 1
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join(".")
8
8
  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: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-22 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.5.1
91
+ rubygems_version: 2.4.5
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: HTML/ERB beautifier