git.iko.soy/typeable/pandoc
on master help sign in
Improved HTML table output (line breaks).
commitbdf23d3a5d621808bb96b6390fa77177daf3907a authorJohn MacFarlane <jgm@berkeley.edu> dateFri 4 Feb 2011, 23:25 (16 years ago) parentbb89fd9
7 files changed+187−70
src/Text/Pandoc/Writers/HTML.hs+17−9 tests/lhs-test.html+2−7 tests/lhs-test.html+lhs+2−7 tests/lhs-test.nohl.html+23−5 tests/lhs-test.nohl.html+lhs+23−5 tests/tables.html+99−30 tests/writer.html+21−7
src/Text/Pandoc/Writers/HTML.hs+17−9
@@ -366,11 +366,12 @@ blockToHtml opts (BlockQuote blocks) =
366366 [OrderedList attribs lst] ->
367367 blockToHtml (opts {writerIncremental = inc})
368368 (OrderedList attribs lst)
369− _ -> blockListToHtml opts blocks >>=
370− (return . blockquote)
369+ _ -> do contents <- blockListToHtml opts blocks
370+ return $ blockquote (nl opts +++
371+ contents +++ nl opts)
371372 else do
372373 contents <- blockListToHtml opts blocks
373− return $ blockquote contents
374+ return $ blockquote (nl opts +++ contents +++ nl opts)
374375blockToHtml opts (Header level lst) = do
375376 contents <- inlineListToHtml opts lst
376377 secnum <- liftM stSecNum get
@@ -431,7 +432,9 @@ blockToHtml opts (DefinitionList lst) = do
431432blockToHtml opts (Table capt aligns widths headers rows') = do
432433 captionDoc <- if null capt
433434 then return noHtml
434− else inlineListToHtml opts capt >>= return . caption
435+ else do
436+ cs <- inlineListToHtml opts capt
437+ return $ caption cs +++ nl opts
435438 let percent w = show (truncate (100*w) :: Integer) ++ "%"
436439 let widthAttrs w = if writerHtml5 opts
437440 then [thestyle $ "width: " ++ percent w]
@@ -439,13 +442,17 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
439442 let coltags = if all (== 0.0) widths
440443 then noHtml
441444 else concatHtml $ map
442− (\w -> col ! (widthAttrs w) $ noHtml) widths
445+ (\w -> (col ! (widthAttrs w)) noHtml +++ nl opts)
446+ widths
443447 head' <- if all null headers
444448 then return noHtml
445− else liftM (thead <<) $ tableRowToHtml opts aligns 0 headers
446− body' <- liftM (tbody <<) $
449+ else do
450+ contents <- tableRowToHtml opts aligns 0 headers
451+ return $ thead << (nl opts +++ contents) +++ nl opts
452+ body' <- liftM (\x -> tbody << (nl opts +++ x)) $
447453 zipWithM (tableRowToHtml opts aligns) [1..] rows'
448− return $ table $ captionDoc +++ coltags +++ head' +++ body'
454+ return $ table $ nl opts +++ captionDoc +++ coltags +++ head' +++
455+ body' +++ nl opts
449456
450457tableRowToHtml :: WriterOptions
451458 -> [Alignment]
@@ -461,7 +468,8 @@ tableRowToHtml opts aligns rownum cols' = do
461468 cols'' <- sequence $ zipWith
462469 (\alignment item -> tableItemToHtml opts mkcell alignment item)
463470 aligns cols'
464− return $ (tr ! [theclass rowclass] $ toHtmlFromList cols'') +++ nl opts
471+ return $ (tr ! [theclass rowclass] $ nl opts +++ toHtmlFromList cols'')
472+ +++ nl opts
465473
466474alignmentToString :: Alignment -> [Char]
467475alignmentToString alignment = case alignment of
tests/lhs-test.html+2−7
@@ -26,19 +26,14 @@ code.sourceCode span.er { color: red; font-weight: bold; }
2626</head>
2727<body>
2828<h1 id="lhs-test">lhs test</h1>
29−
3029<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
31−
3230<pre class="sourceCode"><code class="sourceCode haskell"><span class="ot">unsplit </span><span class="ot">::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d<br />unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span> <br /> <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
33−
3431<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
35−
3632<pre><code>f *** g = first f &gt;&gt;&gt; second g
3733</code></pre>
38−
3934<p>Block quote:</p>
40−
4135<blockquote>
42−<p>foo bar</p></blockquote>
36+<p>foo bar</p>
37+</blockquote>
4338</body>
4439</html>
tests/lhs-test.html+lhs+2−7
@@ -26,19 +26,14 @@ code.sourceCode span.er { color: red; font-weight: bold; }
2626</head>
2727<body>
2828<h1 id="lhs-test">lhs test</h1>
29−
3029<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
31−
3230<pre class="sourceCode"><code class="sourceCode haskell">&gt; <span class="ot">unsplit </span><span class="ot">::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d<br />&gt; unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span> <br />&gt; <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
33−
3431<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
35−
3632<pre><code>f *** g = first f &gt;&gt;&gt; second g
3733</code></pre>
38−
3934<p>Block quote:</p>
40−
4135<blockquote>
42−<p>foo bar</p></blockquote>
36+<p>foo bar</p>
37+</blockquote>
4338</body>
4439</html>
tests/lhs-test.nohl.html+23−5
@@ -4,18 +4,36 @@
44 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55 <meta name="generator" content="pandoc" />
66 <title></title>
7+ <style type="text/css">
8+table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre
9+ { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
10+td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
11+td.sourceCode { padding-left: 5px; }
12+code.sourceCode span.kw { color: #007020; font-weight: bold; }
13+code.sourceCode span.dt { color: #902000; }
14+code.sourceCode span.dv { color: #40a070; }
15+code.sourceCode span.bn { color: #40a070; }
16+code.sourceCode span.fl { color: #40a070; }
17+code.sourceCode span.ch { color: #4070a0; }
18+code.sourceCode span.st { color: #4070a0; }
19+code.sourceCode span.co { color: #60a0b0; font-style: italic; }
20+code.sourceCode span.ot { color: #007020; }
21+code.sourceCode span.al { color: red; font-weight: bold; }
22+code.sourceCode span.fu { color: #06287e; }
23+code.sourceCode span.re { }
24+code.sourceCode span.er { color: red; font-weight: bold; }
25+ </style>
726</head>
827<body>
928<h1 id="lhs-test">lhs test</h1>
1029<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
11−<pre class="sourceCode haskell"><code>unsplit :: (Arrow a) =&gt; (b -&gt; c -&gt; d) -&gt; a (b, c) d
12−unsplit = arr . uncurry
13− -- arr (\op (x,y) -&gt; x `op` y)
14−</code></pre>
30+<pre class="sourceCode"><code class="sourceCode haskell"><span class="ot">unsplit </span><span class="ot">::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d<br />unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span> <br /> <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
1531<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
1632<pre><code>f *** g = first f &gt;&gt;&gt; second g
1733</code></pre>
1834<p>Block quote:</p>
19−<blockquote><p>foo bar</p></blockquote>
35+<blockquote>
36+<p>foo bar</p>
37+</blockquote>
2038</body>
2139</html>
tests/lhs-test.nohl.html+lhs+23−5
@@ -4,18 +4,36 @@
44 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55 <meta name="generator" content="pandoc" />
66 <title></title>
7+ <style type="text/css">
8+table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre
9+ { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
10+td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
11+td.sourceCode { padding-left: 5px; }
12+code.sourceCode span.kw { color: #007020; font-weight: bold; }
13+code.sourceCode span.dt { color: #902000; }
14+code.sourceCode span.dv { color: #40a070; }
15+code.sourceCode span.bn { color: #40a070; }
16+code.sourceCode span.fl { color: #40a070; }
17+code.sourceCode span.ch { color: #4070a0; }
18+code.sourceCode span.st { color: #4070a0; }
19+code.sourceCode span.co { color: #60a0b0; font-style: italic; }
20+code.sourceCode span.ot { color: #007020; }
21+code.sourceCode span.al { color: red; font-weight: bold; }
22+code.sourceCode span.fu { color: #06287e; }
23+code.sourceCode span.re { }
24+code.sourceCode span.er { color: red; font-weight: bold; }
25+ </style>
726</head>
827<body>
928<h1 id="lhs-test">lhs test</h1>
1029<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to return a single value:</p>
11−<pre class="sourceCode literate haskell"><code>&gt; unsplit :: (Arrow a) =&gt; (b -&gt; c -&gt; d) -&gt; a (b, c) d
12−&gt; unsplit = arr . uncurry
13−&gt; -- arr (\op (x,y) -&gt; x `op` y)
14−</code></pre>
30+<pre class="sourceCode"><code class="sourceCode haskell">&gt; <span class="ot">unsplit </span><span class="ot">::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d<br />&gt; unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span> <br />&gt; <span class="co">-- arr (\op (x,y) -&gt; x `op` y) </span></code></pre>
1531<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).</p>
1632<pre><code>f *** g = first f &gt;&gt;&gt; second g
1733</code></pre>
1834<p>Block quote:</p>
19−<blockquote><p>foo bar</p></blockquote>
35+<blockquote>
36+<p>foo bar</p>
37+</blockquote>
2038</body>
2139</html>
tests/tables.html+99−30
@@ -1,129 +1,198 @@
11<p>Simple table with caption:</p>
2−<table><caption>Demonstration of simple table syntax.</caption><thead><tr class="header"><th align="right">Right</th>
2+<table>
3+<caption>Demonstration of simple table syntax.</caption>
4+<thead>
5+<tr class="header">
6+<th align="right">Right</th>
37<th align="left">Left</th>
48<th align="center">Center</th>
59<th align="left">Default</th>
610</tr>
7−</thead><tbody><tr class="odd"><td align="right">12</td>
11+</thead>
12+<tbody>
13+<tr class="odd">
14+<td align="right">12</td>
815<td align="left">12</td>
916<td align="center">12</td>
1017<td align="left">12</td>
1118</tr>
12−<tr class="even"><td align="right">123</td>
19+<tr class="even">
20+<td align="right">123</td>
1321<td align="left">123</td>
1422<td align="center">123</td>
1523<td align="left">123</td>
1624</tr>
17−<tr class="odd"><td align="right">1</td>
25+<tr class="odd">
26+<td align="right">1</td>
1827<td align="left">1</td>
1928<td align="center">1</td>
2029<td align="left">1</td>
2130</tr>
22−</tbody></table>
31+</tbody>
32+</table>
2333<p>Simple table without caption:</p>
24−<table><thead><tr class="header"><th align="right">Right</th>
34+<table>
35+<thead>
36+<tr class="header">
37+<th align="right">Right</th>
2538<th align="left">Left</th>
2639<th align="center">Center</th>
2740<th align="left">Default</th>
2841</tr>
29−</thead><tbody><tr class="odd"><td align="right">12</td>
42+</thead>
43+<tbody>
44+<tr class="odd">
45+<td align="right">12</td>
3046<td align="left">12</td>
3147<td align="center">12</td>
3248<td align="left">12</td>
3349</tr>
34−<tr class="even"><td align="right">123</td>
50+<tr class="even">
51+<td align="right">123</td>
3552<td align="left">123</td>
3653<td align="center">123</td>
3754<td align="left">123</td>
3855</tr>
39−<tr class="odd"><td align="right">1</td>
56+<tr class="odd">
57+<td align="right">1</td>
4058<td align="left">1</td>
4159<td align="center">1</td>
4260<td align="left">1</td>
4361</tr>
44−</tbody></table>
62+</tbody>
63+</table>
4564<p>Simple table indented two spaces:</p>
46−<table><caption>Demonstration of simple table syntax.</caption><thead><tr class="header"><th align="right">Right</th>
65+<table>
66+<caption>Demonstration of simple table syntax.</caption>
67+<thead>
68+<tr class="header">
69+<th align="right">Right</th>
4770<th align="left">Left</th>
4871<th align="center">Center</th>
4972<th align="left">Default</th>
5073</tr>
51−</thead><tbody><tr class="odd"><td align="right">12</td>
74+</thead>
75+<tbody>
76+<tr class="odd">
77+<td align="right">12</td>
5278<td align="left">12</td>
5379<td align="center">12</td>
5480<td align="left">12</td>
5581</tr>
56−<tr class="even"><td align="right">123</td>
82+<tr class="even">
83+<td align="right">123</td>
5784<td align="left">123</td>
5885<td align="center">123</td>
5986<td align="left">123</td>
6087</tr>
61−<tr class="odd"><td align="right">1</td>
88+<tr class="odd">
89+<td align="right">1</td>
6290<td align="left">1</td>
6391<td align="center">1</td>
6492<td align="left">1</td>
6593</tr>
66−</tbody></table>
94+</tbody>
95+</table>
6796<p>Multiline table with caption:</p>
68−<table><caption>Here's the caption. It may span multiple lines.</caption><col width="15%" /><col width="13%" /><col width="16%" /><col width="33%" /><thead><tr class="header"><th align="center">Centered Header</th>
97+<table>
98+<caption>Here's the caption. It may span multiple lines.</caption>
99+<col width="15%" />
100+<col width="13%" />
101+<col width="16%" />
102+<col width="33%" />
103+<thead>
104+<tr class="header">
105+<th align="center">Centered Header</th>
69106<th align="left">Left Aligned</th>
70107<th align="right">Right Aligned</th>
71108<th align="left">Default aligned</th>
72109</tr>
73−</thead><tbody><tr class="odd"><td align="center">First</td>
110+</thead>
111+<tbody>
112+<tr class="odd">
113+<td align="center">First</td>
74114<td align="left">row</td>
75115<td align="right">12.0</td>
76116<td align="left">Example of a row that spans multiple lines.</td>
77117</tr>
78−<tr class="even"><td align="center">Second</td>
118+<tr class="even">
119+<td align="center">Second</td>
79120<td align="left">row</td>
80121<td align="right">5.0</td>
81122<td align="left">Here's another one. Note the blank line between rows.</td>
82123</tr>
83−</tbody></table>
124+</tbody>
125+</table>
84126<p>Multiline table without caption:</p>
85−<table><col width="15%" /><col width="13%" /><col width="16%" /><col width="33%" /><thead><tr class="header"><th align="center">Centered Header</th>
127+<table>
128+<col width="15%" />
129+<col width="13%" />
130+<col width="16%" />
131+<col width="33%" />
132+<thead>
133+<tr class="header">
134+<th align="center">Centered Header</th>
86135<th align="left">Left Aligned</th>
87136<th align="right">Right Aligned</th>
88137<th align="left">Default aligned</th>
89138</tr>
90−</thead><tbody><tr class="odd"><td align="center">First</td>
139+</thead>
140+<tbody>
141+<tr class="odd">
142+<td align="center">First</td>
91143<td align="left">row</td>
92144<td align="right">12.0</td>
93145<td align="left">Example of a row that spans multiple lines.</td>
94146</tr>
95−<tr class="even"><td align="center">Second</td>
147+<tr class="even">
148+<td align="center">Second</td>
96149<td align="left">row</td>
97150<td align="right">5.0</td>
98151<td align="left">Here's another one. Note the blank line between rows.</td>
99152</tr>
100−</tbody></table>
153+</tbody>
154+</table>
101155<p>Table without column headers:</p>
102−<table><tbody><tr class="odd"><td align="right">12</td>
156+<table>
157+<tbody>
158+<tr class="odd">
159+<td align="right">12</td>
103160<td align="left">12</td>
104161<td align="center">12</td>
105162<td align="right">12</td>
106163</tr>
107−<tr class="even"><td align="right">123</td>
164+<tr class="even">
165+<td align="right">123</td>
108166<td align="left">123</td>
109167<td align="center">123</td>
110168<td align="right">123</td>
111169</tr>
112−<tr class="odd"><td align="right">1</td>
170+<tr class="odd">
171+<td align="right">1</td>
113172<td align="left">1</td>
114173<td align="center">1</td>
115174<td align="right">1</td>
116175</tr>
117−</tbody></table>
176+</tbody>
177+</table>
118178<p>Multiline table without column headers:</p>
119−<table><col width="15%" /><col width="13%" /><col width="16%" /><col width="33%" /><tbody><tr class="odd"><td align="center">First</td>
179+<table>
180+<col width="15%" />
181+<col width="13%" />
182+<col width="16%" />
183+<col width="33%" />
184+<tbody>
185+<tr class="odd">
186+<td align="center">First</td>
120187<td align="left">row</td>
121188<td align="right">12.0</td>
122189<td align="left">Example of a row that spans multiple lines.</td>
123190</tr>
124−<tr class="even"><td align="center">Second</td>
191+<tr class="even">
192+<td align="center">Second</td>
125193<td align="left">row</td>
126194<td align="right">5.0</td>
127195<td align="left">Here's another one. Note the blank line between rows.</td>
128196</tr>
129−</tbody></table>
197+</tbody>
198+</table>
tests/writer.html+21−7
@@ -32,8 +32,11 @@
3232<hr />
3333<h1 id="block-quotes">Block Quotes</h1>
3434<p>E-mail style:</p>
35−<blockquote><p>This is a block quote. It is pretty short.</p></blockquote>
36−<blockquote><p>Code in a block quote:</p>
35+<blockquote>
36+<p>This is a block quote. It is pretty short.</p>
37+</blockquote>
38+<blockquote>
39+<p>Code in a block quote:</p>
3740<pre><code>sub status {
3841 print &quot;working&quot;;
3942}
@@ -44,8 +47,13 @@
4447<li>item two</li>
4548</ol>
4649<p>Nested block quotes:</p>
47−<blockquote><p>nested</p></blockquote>
48−<blockquote><p>nested</p></blockquote></blockquote>
50+<blockquote>
51+<p>nested</p>
52+</blockquote>
53+<blockquote>
54+<p>nested</p>
55+</blockquote>
56+</blockquote>
4957<p>This should not be a block quote: 2 &gt; 1.</p>
5058<p>And a following paragraph.</p>
5159<hr />
@@ -262,7 +270,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
262270<dd><p>orange fruit</p>
263271<pre><code>{ orange code block }
264272</code></pre>
265−<blockquote><p>orange block quote</p></blockquote>
273+<blockquote>
274+<p>orange block quote</p>
275+</blockquote>
266276</dd>
267277</dl>
268278<p>Multiple definitions, tight:</p>
@@ -523,7 +533,9 @@ h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';
523533document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+'a'+'>');
524534// -->
525535</script><noscript>&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript></p>
526−<blockquote><p>Blockquoted: <a href="http://example.com/"><code class="url">http://example.com/</code></a></p></blockquote>
536+<blockquote>
537+<p>Blockquoted: <a href="http://example.com/"><code class="url">http://example.com/</code></a></p>
538+</blockquote>
527539<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
528540<pre><code>or here: &lt;http://example.com/&gt;
529541</code></pre>
@@ -537,7 +549,9 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
537549<hr />
538550<h1 id="footnotes">Footnotes</h1>
539551<p>Here is a footnote reference,<sup><a href="#fn1" class="footnoteRef" id="fnref1">1</a></sup> and another.<sup><a href="#fn2" class="footnoteRef" id="fnref2">2</a></sup> This should <em>not</em> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<sup><a href="#fn3" class="footnoteRef" id="fnref3">3</a></sup></p>
540−<blockquote><p>Notes can go in quotes.<sup><a href="#fn4" class="footnoteRef" id="fnref4">4</a></sup></p></blockquote>
552+<blockquote>
553+<p>Notes can go in quotes.<sup><a href="#fn4" class="footnoteRef" id="fnref4">4</a></sup></p>
554+</blockquote>
541555<ol style="list-style-type: decimal">
542556<li>And in list items.<sup><a href="#fn5" class="footnoteRef" id="fnref5">5</a></sup></li>
543557</ol>