h5-min 0.1.0 → 0.1.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/fixtures/pre.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <title>Untitled</title>
4
4
  <pre>
5
5
  This
6
- is
6
+ <b>is</b>
7
7
  pre-formatted .
8
-
8
+ and in<code>code</code>
9
9
  </pre>
@@ -1,6 +1,6 @@
1
1
  <!doctype html><meta charset=utf-8><title>Untitled</title><pre>
2
2
  This
3
- is
3
+ <b>is</b>
4
4
  pre-formatted .
5
-
5
+ and in<code>code</code>
6
6
  </pre>
data/lib/h5-min.rb CHANGED
@@ -18,10 +18,9 @@ module HTML5
18
18
 
19
19
  @minifier ||= Class.new(Nokogiri::XML::SAX::Document) do
20
20
 
21
- attr_accessor :in_pre, :buf, :text_node, :entities
21
+ attr_accessor :buf, :text_node, :entities
22
22
 
23
23
  def initialize
24
- @in_pre = false
25
24
  @buf, @text_node = '', ''
26
25
  @stack = []
27
26
  @entities = HTMLEntities.new :expanded
@@ -36,16 +35,14 @@ module HTML5
36
35
  name = normalise_name name
37
36
  dump_text_node
38
37
  @stack.push name
39
- self.in_pre = true if PRE_TAGS.include?(name)
40
38
  buf << "<#{name}" + format_attributes(attrs) + ">"
41
39
  end
42
40
 
43
41
  def end_element name
44
42
  name = normalise_name name
45
43
  dump_text_node
44
+ buf.rstrip! unless in_pre_element?
46
45
  @stack.pop
47
- buf.rstrip! unless in_pre
48
- self.in_pre = PRE_TAGS.include?(name)
49
46
  buf << "</#{name}>"
50
47
  end
51
48
 
@@ -99,7 +96,7 @@ module HTML5
99
96
 
100
97
  def format_text_node
101
98
  text = format_entities text_node
102
- return text if in_pre
99
+ return text if in_pre_element?
103
100
  text.gsub!(/[\n\t]/,'')
104
101
  # Don't strip inter-element white space for flow elements
105
102
  unless buf =~ %r{</\w+>\s*\Z} and in_flow_element?
@@ -112,6 +109,10 @@ module HTML5
112
109
  not (FLOW_ELEMENTS & @stack).empty?
113
110
  end
114
111
 
112
+ def in_pre_element?
113
+ not (PRE_TAGS & @stack).empty?
114
+ end
115
+
115
116
  def dump_text_node
116
117
  buf << format_text_node
117
118
  text_node.clear
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Run Paint Run Run