mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] [html2haml] Properly parse conditional comments.
This commit is contained in:
parent
d18f8bfdcd
commit
4ccb75c4df
3 changed files with 32 additions and 3 deletions
|
@ -90,6 +90,8 @@ including the line number and the offending character.
|
|||
* Self-closing tags (such as `<br />`) are now transformed into
|
||||
self-closing Haml tags (like `%br/`).
|
||||
|
||||
* IE conditional comments are now properly parsed.
|
||||
|
||||
* Attributes are now output in a more-standard format,
|
||||
without spaces within the curly braces
|
||||
(e.g. `%p{:foo => "bar"}` as opposed to `%p{ :foo => "bar" }`).
|
||||
|
|
|
@ -204,10 +204,16 @@ module Haml
|
|||
class ::Hpricot::Comment
|
||||
# @see Haml::HTML::Node#to_haml
|
||||
def to_haml(tabs, options)
|
||||
if self.content.include?("\n")
|
||||
"#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
|
||||
content = self.content
|
||||
if content =~ /\A(\[[^\]]+\])>(.*)<!\[endif\]\z/m
|
||||
condition = $1
|
||||
content = $2
|
||||
end
|
||||
|
||||
if content.include?("\n")
|
||||
"#{tabulate(tabs)}/#{condition}\n#{parse_text(content, tabs + 1)}"
|
||||
else
|
||||
"#{tabulate(tabs)}/ #{self.content.strip}"
|
||||
"#{tabulate(tabs)}/#{condition} #{content.strip}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -173,6 +173,27 @@ baz</code>
|
|||
HTML
|
||||
end
|
||||
|
||||
def test_conditional_comment
|
||||
assert_equal(<<HAML.rstrip, render(<<HTML))
|
||||
/[if foo]
|
||||
bar
|
||||
baz
|
||||
HAML
|
||||
<!--[if foo]>
|
||||
bar
|
||||
baz
|
||||
<![endif]-->
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_inline_conditional_comment
|
||||
assert_equal(<<HAML.rstrip, render(<<HTML))
|
||||
/[if foo] bar baz
|
||||
HAML
|
||||
<!--[if foo]> bar baz <![endif]-->
|
||||
HTML
|
||||
end
|
||||
|
||||
## ERB
|
||||
|
||||
def test_erb
|
||||
|
|
Loading…
Add table
Reference in a new issue