mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Add support for CDATA tags to html2haml.
This commit is contained in:
parent
d19db97cdc
commit
dabfd0bef9
2 changed files with 23 additions and 3 deletions
|
@ -78,9 +78,7 @@ module Haml
|
|||
|
||||
class ::Hpricot::Doc
|
||||
def to_haml(tabs = 0)
|
||||
output = ''
|
||||
children.each { |child| output += child.to_haml(0) } if children
|
||||
output
|
||||
(children || []).inject('') {|s, c| s << c.to_haml(0)}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,6 +88,12 @@ module Haml
|
|||
end
|
||||
end
|
||||
|
||||
class ::Hpricot::CData
|
||||
def to_haml(tabs = 0)
|
||||
"#{tabulate(tabs)}:cdata\n#{parse_text(self.content, tabs + 1)}"
|
||||
end
|
||||
end
|
||||
|
||||
class ::Hpricot::DocType
|
||||
def to_haml(tabs = 0)
|
||||
attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
|
||||
|
|
|
@ -74,6 +74,22 @@ class Html2HamlTest < Test::Unit::TestCase
|
|||
render_rhtml(%Q{<%- form_for -%>})
|
||||
end
|
||||
|
||||
def test_cdata
|
||||
assert_equal(<<HAML.strip, render(<<HTML))
|
||||
%p
|
||||
:cdata
|
||||
<a foo="bar" baz="bang">
|
||||
<div id="foo">flop</div>
|
||||
</a>
|
||||
HAML
|
||||
<p><![CDATA[
|
||||
<a foo="bar" baz="bang">
|
||||
<div id="foo">flop</div>
|
||||
</a>
|
||||
]]></p>
|
||||
HTML
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render(text, options = {})
|
||||
|
|
Loading…
Reference in a new issue