Better text/html serialization

For the Andrew Staceys of this world:
deal with empty element in a more
text/html-friendly fashion.
master
Jacques Distler 2011-08-27 02:40:40 -05:00
parent 27ad6ff2a8
commit 2d303d54a0
20 changed files with 41 additions and 41 deletions

View File

@ -45,7 +45,7 @@ class PageRendererTest < ActiveSupport::TestCase
end
def test_wiki_links_after_empty
assert_markup_parsed_as(%{<code/>\n<p>This is a <span class='newWikiWord'>wikilink<a href=} +
assert_markup_parsed_as(%{<code></code>\n<p>This is a <span class='newWikiWord'>wikilink<a href=} +
%{'../show/wikilink'>?</a></span>.</p>},
"<code></code>\n\nThis is a [[wikilink]].")
end
@ -55,7 +55,7 @@ class PageRendererTest < ActiveSupport::TestCase
"would be <a class='existingWikiWord' href='../show/MyWay'>My Way</a> " +
"<math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>" +
"<mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics>" +
"<annotation-xml encoding='SVG1.1'><svg/></annotation-xml></semantics></math> in kinda " +
"<annotation-xml encoding='SVG1.1'><svg></svg></annotation-xml></semantics></math> in kinda " +
"<a class='existingWikiWord' href='../show/ThatWay'>That Way</a> in " +
"<span class='newWikiWord'>His Way<a href='../show/HisWay'>?</a></span> " +
%{though <a class='existingWikiWord' href='../show/MyWay'>My Way</a> OverThere \342\200\223 see } +
@ -164,7 +164,7 @@ END_THM
%{<div class='maruku-equation'><math class='maruku-mathml' display='block' } +
%{xmlns='http://www.w3.org/1998/Math/MathML'><mi>sin</mi><mo stretchy='false'>} +
%{(</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics><annotation-xml encoding='SVG1.1'>} +
%{<svg/></annotation-xml></semantics></math><span class='maruku-eq-tex'><code style='display: none;'>} +
%{<svg></svg></annotation-xml></semantics></math><span class='maruku-eq-tex'><code style='display: none;'>} +
%{\\sin(x) \\begin{svg}&lt;svg/&gt;\\end{svg}</code></span></div>},
"$$\\sin(x) \\begin{svg}<svg/>\\end{svg}$$")
@ -601,7 +601,7 @@ END_THM
# currently, upper case HTML elements are not allowed
assert_markup_parsed_as(
"<p>This &lt;IMG SRC='http://hobix.com/sample.jpg' alt=''/&gt; is an inline image link.</p>",
"<p>This &lt;IMG SRC='http://hobix.com/sample.jpg' alt=''&gt;&lt;/IMG&gt; is an inline image link.</p>",
'This <IMG SRC="http://hobix.com/sample.jpg" alt="" /> is an inline image link.')
end
@ -659,7 +659,7 @@ END_THM
"<a class='existingWikiWord' href='MyWay.html'>My Way</a> " +
"<math class='maruku-mathml' display='inline' xmlns='http://www.w3.org/1998/Math/MathML'>" +
"<mi>sin</mi><mo stretchy='false'>(</mo><mi>x</mi><mo stretchy='false'>)</mo><semantics>" +
"<annotation-xml encoding='SVG1.1'><svg/></annotation-xml></semantics></math> in kinda " +
"<annotation-xml encoding='SVG1.1'><svg></svg></annotation-xml></semantics></math> in kinda " +
"<a class='existingWikiWord' href='ThatWay.html'>That Way</a> in " +
"<span class='newWikiWord'>His Way</span> though " +
%{<a class='existingWikiWord' href='MyWay.html'>My Way</a> OverThere \342\200\223 see } +

View File

@ -107,14 +107,14 @@ require 'maruku/string_utils'
end
if (content_only)
xml = body.to_xml(:indent => (context[:indent] || 2), :save_with => 2 )
xml = body.to_xml(:indent => (context[:indent] || 2), :save_with => 18 )
else
doc2 = Nokogiri::XML::Document.parse("<div>"+S5_external+"</div>")
doc2.root.children.each{ |child| head << child }
add_css_to(head)
xml = html.to_xml(:indent => (context[:indent] || 2), :save_with => 2 )
xml = html.to_xml(:indent => (context[:indent] || 2), :save_with => 18 )
Xhtml11_mathml2_svg11 + xml
end
end

View File

@ -46,7 +46,7 @@ module MaRuKu; module Out; module HTML
d.root << render_footnotes
end
xml = d.to_xml(:indent => (context[:indent] || 2), :save_with => 2 )
xml = d.to_xml(:indent => (context[:indent] || 2), :save_with => 18 )
xml.gsub!(/\A<dummy>\s*|\s*<\/dummy>\s*\Z|\A<dummy\s*\/>/,'')
xml
@ -59,7 +59,7 @@ module MaRuKu; module Out; module HTML
doc = to_html_document_tree
xml = ""
xml = doc.to_xml(:indent => (context[:indent] || 2), :save_with => 2 )
xml = doc.to_xml(:indent => (context[:indent] || 2), :save_with => 18 )
Xhtml11_mathml2_svg11 + xml
end

View File

@ -8,7 +8,7 @@ Write a comment here
*** Output of inspect ***
md_el(:document,[md_par([md_im_image(["bar"], "/foo.jpg", nil)])],{},[])
*** Output of to_html ***
<p><img src="/foo.jpg" alt="bar"/></p>
<p><img src="/foo.jpg" alt="bar" /></p>
*** Output of to_latex ***
*** Output of to_md ***

View File

@ -57,7 +57,7 @@ md_el(:document,[
<p>That&#8217;s some text with a footnote <sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> and another <sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> and another <sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup>.</p>
<p>This is not a footnote.</p>
<div class="footnotes"><hr/><ol><li id="fn:1">
<div class="footnotes"><hr /><ol><li id="fn:1">
<p>And that&#8217;s the footnote. This is second sentence (same paragraph). <a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li><li id="fn:2">
<p>This is the very long one.</p>

View File

@ -22,7 +22,7 @@ md_el(:document,[
md_el(:hrule,[],{},[])
],{},[])
*** Output of to_html ***
<hr/><hr/><hr/><hr/><hr/>
<hr /><hr /><hr /><hr /><hr />
*** Output of to_latex ***
\vspace{.5em} \hrule \vspace{.5em}

View File

@ -12,8 +12,8 @@ md_el(:document,[
md_html("<div></div>")
],{},[])
*** Output of to_html ***
<p>One <div/>123</p>
<div/>
<p>One <div></div>123</p>
<div></div>
*** Output of to_latex ***
One 123
*** Output of to_md ***

View File

@ -15,7 +15,7 @@ md_el(:document,[
],{},[])
*** Output of to_html ***
<div class="frame">
<a class="photo" href="http://www.flickr.com/photos/censi/54757256/"><img alt="" moz-do-not-send="true" src="http://static.flickr.com/27/54757256_1a2c1d2a95_m.jpg"/></a>
<a class="photo" href="http://www.flickr.com/photos/censi/54757256/"><img alt="" moz-do-not-send="true" src="http://static.flickr.com/27/54757256_1a2c1d2a95_m.jpg" /></a>
</div>
*** Output of to_latex ***

View File

@ -13,7 +13,7 @@ md_el(:document,[
],{},[])
*** Output of to_html ***
<div class="frame">
<a class="photo" href="http://www.flickr.com/photos/censi/88561568/"><img moz-do-not-send="true" src="http://static.flickr.com/28/88561568_ab84d28245_m.jpg" width="240" height="180" alt="Aperitif"/></a>
<a class="photo" href="http://www.flickr.com/photos/censi/88561568/"><img moz-do-not-send="true" src="http://static.flickr.com/28/88561568_ab84d28245_m.jpg" width="240" height="180" alt="Aperitif" /></a>
</div>
*** Output of to_latex ***

View File

@ -31,11 +31,11 @@ md_el(:document,[
<pre><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;</code></pre>
<pre class="xml"><code lang="xml"><span class="punct">&lt;</span><span class="tag">p</span><span class="punct">&gt;</span>here's an apostrophe &amp; a quote "<span class="punct">&lt;/</span><span class="tag">p</span><span class="punct">&gt;</span></code></pre>
<pre class="xml"><code lang="xml" xml:lang="xml"><span class="punct">&lt;</span><span class="tag">p</span><span class="punct">&gt;</span>here's an apostrophe &amp; a quote "<span class="punct">&lt;/</span><span class="tag">p</span><span class="punct">&gt;</span></code></pre>
<pre class="not_supported"><code lang="not_supported">&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;</code></pre>
<pre class="not_supported"><code lang="not_supported" xml:lang="not_supported">&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;</code></pre>
<pre class="xml"><code lang="xml"><span class="punct">&lt;</span><span class="tag">p</span><span class="punct">&gt;</span>here's an apostrophe &amp; a quote "<span class="punct">&lt;/</span><span class="tag">p</span><span class="punct">&gt;</span></code></pre>
<pre class="xml"><code lang="xml" xml:lang="xml"><span class="punct">&lt;</span><span class="tag">p</span><span class="punct">&gt;</span>here's an apostrophe &amp; a quote "<span class="punct">&lt;/</span><span class="tag">p</span><span class="punct">&gt;</span></code></pre>
*** Output of to_latex ***
{\colorbox[rgb]{1.00,0.93,1.00}{\tt \char60p\char62here\char39s~an~apostrophe~\char38~a~quote~\char34\char60\char47p\char62}}

View File

@ -52,15 +52,15 @@ md_el(:document,[
md_ref_def("css2", "http://jigsaw.w3.org/css-validator/images/vcss", {:title=>"Optional title attribute"})
],{},[])
*** Output of to_html ***
<p>This page does not utilize <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets"/></p>
<p>This page does not utilize <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" /></p>
<p>Please mouseover to see the title: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Title ok!"/></p>
<p>Please mouseover to see the title: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Title ok!" /></p>
<p>Please mouseover to see the title: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Title ok!"/></p>
<p>Please mouseover to see the title: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Title ok!" /></p>
<p>I&#8217;ll say it one more time: this page does not use <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Optional title attribute"/></p>
<p>I&#8217;ll say it one more time: this page does not use <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Optional title attribute" /></p>
<p>This is double size: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Optional title attribute"/></p>
<p>This is double size: <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Cascading Style Sheets" title="Optional title attribute" /></p>
*** Output of to_latex ***
This page does not utilize

View File

@ -16,9 +16,9 @@ md_el(:document,[
md_ref_def("image", "image.jpg", {:title=>nil})
],{},[])
*** Output of to_html ***
<p>This is an <img src="image.jpg" alt="image"/>.</p>
<p>This is an <img src="image.jpg" alt="image" />.</p>
<p>This is an <img src="image.jpg" alt="image"/>.</p>
<p>This is an <img src="image.jpg" alt="image" />.</p>
*** Output of to_latex ***
This is an .

View File

@ -73,12 +73,12 @@ md_el(:document,[
<pre><code>&lt;img src="http://jigsaw.w3.org/css-validator/images/vcss"/&gt;</code></pre>
<p>Result on span: <img src="http://jigsaw.w3.org/css-validator/images/vcss"/></p>
<p>Result on span: <img src="http://jigsaw.w3.org/css-validator/images/vcss" /></p>
<p>Result alone:</p>
<img src="http://jigsaw.w3.org/css-validator/images/vcss"/>
<img src="http://jigsaw.w3.org/css-validator/images/vcss" />
<p>Without closing:</p>
<img src="http://jigsaw.w3.org/css-validator/images/vcss"/><div>
<img src="http://jigsaw.w3.org/css-validator/images/vcss" /><div>
<p>
<p>This is</p>
<em>

View File

@ -102,9 +102,9 @@ md_el(:document,[
<p>Paragraph (1 space after), list with no space: * ciao</p>
<p>Paragraph (2 spaces after), list with no space:<br/>* ciao</p>
<p>Paragraph (2 spaces after), list with no space:<br />* ciao</p>
<p>Paragraph (3 spaces after), list with no space: <br/>* ciao</p>
<p>Paragraph (3 spaces after), list with no space: <br />* ciao</p>
<p>Paragraph with block quote:</p>
@ -120,7 +120,7 @@ md_el(:document,[
<h2 id="header_2">header</h2>
<p>Paragraph with html after <div/></p>
<p>Paragraph with html after <div></div></p>
<p>Paragraph with html after, indented: <em>Emphasis</em></p>

View File

@ -7,7 +7,7 @@ Write a comment here
*** Output of inspect ***
md_el(:document,[md_html("<br />")],{},[])
*** Output of to_html ***
<br/>
<br />
*** Output of to_latex ***
*** Output of to_md ***

View File

@ -74,9 +74,9 @@ md_el(:document,[
<p>Paragraph (1 space after), list with no space: * ciao</p>
<p>Paragraph (2 spaces after), list with no space:<br/>* ciao</p>
<p>Paragraph (2 spaces after), list with no space:<br />* ciao</p>
<p>Paragraph (3 spaces after), list with no space: <br/>* ciao</p>
<p>Paragraph (3 spaces after), list with no space: <br />* ciao</p>
<p>Paragraph with block quote:</p>

View File

@ -28,7 +28,7 @@ md_el(:document,[
<p>Paragraph 2</p>
<p>Paragraph 3 Paragraph 4 Paragraph Br-&gt;<br/>Paragraph 5</p>
<p>Paragraph 3 Paragraph 4 Paragraph Br-&gt;<br />Paragraph 5</p>
*** Output of to_latex ***
Paragraph 1

View File

@ -21,8 +21,8 @@ md_el(:document,[
],{:align=>[:left, :left, :left]},[])
],{},[])
*** Output of to_html ***
<table><thead><tr><th/><th>1</th><th>2</th></tr></thead><tbody><tr><td style="text-align: left;">A</td><td style="text-align: left;">X</td><td style="text-align: left;"/></tr>
<tr><td style="text-align: left;">B</td><td style="text-align: left;"/><td style="text-align: left;">X</td></tr>
<table><thead><tr><th></th><th>1</th><th>2</th></tr></thead><tbody><tr><td style="text-align: left;">A</td><td style="text-align: left;">X</td><td style="text-align: left;"></td></tr>
<tr><td style="text-align: left;">B</td><td style="text-align: left;"></td><td style="text-align: left;">X</td></tr>
</tbody></table>
*** Output of to_latex ***
\begin{tabular}{l|l|l}

View File

@ -31,7 +31,7 @@ puts Maruku.new($stdin).to_html</code></pre>
<p>This is ruby code:</p>
<pre class="ruby"><code lang="ruby"><span class="ident">require</span> <span class="punct">'</span><span class="string">maruku</span><span class="punct">'</span></code></pre>
<pre class="ruby"><code lang="ruby" xml:lang="ruby"><span class="ident">require</span> <span class="punct">'</span><span class="string">maruku</span><span class="punct">'</span></code></pre>
<pre><code>puts Maruku.new($stdin).to_html</code></pre>
*** Output of to_latex ***

View File

@ -29,10 +29,10 @@ md_el(:document,[
],{},[])
],{},[])
*** Output of to_html ***
<p>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Break:<br/>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet.</p>
<p>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Break:<br />Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet.</p>
<ul>
<li>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet Lorem ipsum Break:<br/>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet</li>
<li>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet Lorem ipsum Break:<br />Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet</li>
<li>Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet. Lorem ipsum dolor amet</li>
</ul>