[Haml] [html2haml] Use :preserve for <pre> and <textarea>.
This commit is contained in:
parent
d851ff5b19
commit
98cae30c97
|
@ -71,6 +71,21 @@ including the line number and the offending character.
|
|||
return 12;
|
||||
}
|
||||
|
||||
* `<pre>` and `<textarea>` tags are now transformed into the `:preserve` filter.
|
||||
For example:
|
||||
|
||||
<pre>Foo
|
||||
bar
|
||||
baz</pre>
|
||||
|
||||
is now transformed into:
|
||||
|
||||
%pre
|
||||
:preserve
|
||||
Foo
|
||||
bar
|
||||
baz
|
||||
|
||||
* 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" }`).
|
||||
|
|
|
@ -241,10 +241,16 @@ module Haml
|
|||
|
||||
if children && children.size == 1
|
||||
child = children.first
|
||||
if child.is_a?(::Hpricot::Text) && !child.to_s.include?("\n")
|
||||
text = child.to_haml(tabs + 1, options)
|
||||
return output + " " + text.lstrip unless text.chomp.include?("\n")
|
||||
return output + "\n" + text
|
||||
if child.is_a?(::Hpricot::Text)
|
||||
if !child.to_s.include?("\n")
|
||||
text = child.to_haml(tabs + 1, options)
|
||||
return output + " " + text.lstrip unless text.chomp.include?("\n")
|
||||
return output + "\n" + text
|
||||
elsif ["pre", "textarea"].include?(name) ||
|
||||
(name == "code" && parent.is_a?(::Hpricot::Elem) && parent.name == "pre")
|
||||
return output + "\n#{tabulate(tabs + 1)}:preserve\n" +
|
||||
innerText.gsub(/^/, tabulate(tabs + 2))
|
||||
end
|
||||
elsif child.is_a?(::Hpricot::Elem) && child.name == "haml:loud"
|
||||
return output + child.to_haml(tabs + 1, options).lstrip
|
||||
end
|
||||
|
|
|
@ -116,6 +116,48 @@ HAML
|
|||
HTML
|
||||
end
|
||||
|
||||
def test_pre
|
||||
assert_equal(<<HAML.rstrip, render(<<HTML))
|
||||
%pre
|
||||
:preserve
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
HAML
|
||||
<pre>foo
|
||||
bar
|
||||
baz</pre>
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_pre_code
|
||||
assert_equal(<<HAML.rstrip, render(<<HTML))
|
||||
%pre
|
||||
%code
|
||||
:preserve
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
HAML
|
||||
<pre><code>foo
|
||||
bar
|
||||
baz</code></pre>
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_code_without_pre
|
||||
assert_equal(<<HAML.rstrip, render(<<HTML))
|
||||
%code
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
HAML
|
||||
<code>foo
|
||||
bar
|
||||
baz</code>
|
||||
HTML
|
||||
end
|
||||
|
||||
## ERB
|
||||
|
||||
def test_erb
|
||||
|
|
Loading…
Reference in New Issue