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 +1 -1
- data/fixtures/pre.html +2 -2
- data/fixtures/pre.html.min +2 -2
- data/lib/h5-min.rb +7 -6
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/fixtures/pre.html
CHANGED
data/fixtures/pre.html.min
CHANGED
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 :
|
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
|
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
|