dolores-cml 0.6.1 → 0.6.2
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/cml.gemspec +1 -1
- data/lib/cml/parser.rb +13 -5
- data/spec/complex_spec.rb +1 -1
- data/spec/fixtures/script-style.cml +5 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
data/cml.gemspec
CHANGED
data/lib/cml/parser.rb
CHANGED
@@ -5,7 +5,7 @@ module CML
|
|
5
5
|
def initialize(content, opts = {})
|
6
6
|
@opts = opts
|
7
7
|
#Because nokogiri is munging my CDATA sections, we parse it out ahead of time
|
8
|
-
@cdata = content.scan(/(<(script|style)[^>]*?>)(.*?)(<\/\2)/m)
|
8
|
+
@cdata = content.scan(/(<(script|style)[^>]*?>)(.*?)(<\/\2>)/m)
|
9
9
|
@doc = Parser.parse(content)
|
10
10
|
@cftags = @doc.xpath("//cml:*[not(ancestor::cml:*)]")
|
11
11
|
normalize if opts[:normalize]
|
@@ -17,7 +17,7 @@ module CML
|
|
17
17
|
def self.parse(content)
|
18
18
|
#This sucks, we remove scripts, styles, and close non self closed tags
|
19
19
|
#We could potentially add CDATA clauses to them, but this is "easier"
|
20
|
-
xhtml = content.gsub(/(<(script|style)[^>]*?>)(.*?)(<\/\2)/m, "\\1\\4").gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>') #base, basefont, area, meta
|
20
|
+
xhtml = content.gsub(/(<(script|style)[^>]*?>)(.*?)(<\/\2>)/m, "\\1\\4").gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>') #base, basefont, area, meta
|
21
21
|
Nokogiri::XML("<root xmlns:cml=\"http://crowdflower.com\">#{xhtml}</root>")
|
22
22
|
end
|
23
23
|
|
@@ -108,7 +108,11 @@ module CML
|
|
108
108
|
def to_cml
|
109
109
|
cml = @doc.to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
|
110
110
|
#Hack to ensure the next sub doesn't match...
|
111
|
-
@cdata.each
|
111
|
+
@cdata.each do |matches|
|
112
|
+
html.sub!(/(<(script|style)[^>]*>)<\/\2>/m) do |m|
|
113
|
+
"#{$1}#{matches[2].empty? ? " " : matches[2]}</#{$2}>"
|
114
|
+
end
|
115
|
+
end
|
112
116
|
cml
|
113
117
|
end
|
114
118
|
|
@@ -116,8 +120,12 @@ module CML
|
|
116
120
|
#We convert the entire document and strip root tags / rando empty tags ALA libxml 2.6.32
|
117
121
|
#We're also adding self closing tags
|
118
122
|
html = convert(opts).to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
|
119
|
-
#Let's re-insert that CDATA
|
120
|
-
@cdata.each
|
123
|
+
#Let's re-insert that CDATA, tricky because scripts will sometimes contain single quotes...
|
124
|
+
@cdata.each do |matches|
|
125
|
+
html.sub!(/(<(script|style)[^>]*>)<\/\2>/m) do |m|
|
126
|
+
"#{$1}#{matches[2].empty? ? " " : matches[2]}</#{$2}>"
|
127
|
+
end
|
128
|
+
end
|
121
129
|
wrap(html)
|
122
130
|
end
|
123
131
|
|
data/spec/complex_spec.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=Knx84fDV34H2VnhVU1DoD7chT1wjJ2r36uf4dZW7Vc5si9sqQRAYU_g8fo7zV.wF"></script>
|
2
2
|
<script src="/javascripts/upload.js" type="text/javascript" charset="utf-8"></script>
|
3
3
|
|
4
|
+
|
4
5
|
<script type="text/javascript">
|
5
|
-
var cool
|
6
|
+
var cool = 'cool\'s'
|
6
7
|
</script>
|
7
|
-
|
8
8
|
<style type="text/css">
|
9
|
-
|
9
|
+
.invisible{
|
10
|
+
a { font: awesome;}
|
11
|
+
}
|
10
12
|
</style>
|