git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Improved table support.

We can now handle all different alignment types, for simple tables only (no captions, no relative widths, cell contents just plain inlines). Other tables are still handled using raw HTML. Addresses #1585 as far as it can be addresssed, I believe.

commita8273009baeeece65b60816e1eb42ae54b977f8d authorJohn MacFarlane <jgm@berkeley.edu> dateSat 30 Aug 2014, 20:34 (12 years ago) parentb509275
2 files changed+20−56
src/Text/Pandoc/Writers/Textile.hs+13−4 tests/tables.textile+7−52
src/Text/Pandoc/Writers/Textile.hs+13−4
@@ -39,6 +39,7 @@ import Text.Pandoc.Templates (renderTemplate')
3939import Text.Pandoc.XML ( escapeStringForXML )
4040import Data.List ( intercalate )
4141import Control.Monad.State
42+import Control.Applicative ((<$>))
4243import Data.Char ( isSpace )
4344
4445data WriterState = WriterState {
@@ -164,14 +165,22 @@ blockToTextile opts (BlockQuote blocks) = do
164165 return $ "<blockquote>\n\n" ++ contents ++ "\n</blockquote>\n"
165166
166167blockToTextile opts (Table [] aligns widths headers rows') |
167− all (==0) widths && all (`elem` [AlignLeft,AlignDefault]) aligns = do
168+ all (==0) widths = do
168169 hs <- mapM (liftM (("_. " ++) . stripTrailingNewlines) . blockListToTextile opts) headers
169170 let cellsToRow cells = "|" ++ intercalate "|" cells ++ "|"
170− let header = if all null headers then "" else cellsToRow hs
171− let rowToCells = mapM (liftM stripTrailingNewlines . blockListToTextile opts)
171+ let header = if all null headers then "" else cellsToRow hs ++ "\n"
172+ let blocksToCell (align, bs) = do
173+ contents <- stripTrailingNewlines <$> blockListToTextile opts bs
174+ let alignMarker = case align of
175+ AlignLeft -> "<. "
176+ AlignRight -> ">. "
177+ AlignCenter -> "=. "
178+ AlignDefault -> ""
179+ return $ alignMarker ++ contents
180+ let rowToCells = mapM blocksToCell . zip aligns
172181 bs <- mapM rowToCells rows'
173182 let body = unlines $ map cellsToRow bs
174− return $ header ++ "\n" ++ body ++ "\n"
183+ return $ header ++ body
175184
176185blockToTextile opts (Table capt aligns widths headers rows') = do
177186 let alignStrings = map alignmentToString aligns
tests/tables.textile+7−52
@@ -34,36 +34,10 @@ Simple table with caption:
3434
3535Simple table without caption:
3636
37−<table>
38−<thead>
39−<tr class="header">
40−<th align="right">Right</th>
41−<th align="left">Left</th>
42−<th align="center">Center</th>
43−<th align="left">Default</th>
44−</tr>
45−</thead>
46−<tbody>
47−<tr class="odd">
48−<td align="right">12</td>
49−<td align="left">12</td>
50−<td align="center">12</td>
51−<td align="left">12</td>
52−</tr>
53−<tr class="even">
54−<td align="right">123</td>
55−<td align="left">123</td>
56−<td align="center">123</td>
57−<td align="left">123</td>
58−</tr>
59−<tr class="odd">
60−<td align="right">1</td>
61−<td align="left">1</td>
62−<td align="center">1</td>
63−<td align="left">1</td>
64−</tr>
65−</tbody>
66−</table>
37+|_. Right|_. Left|_. Center|_. Default|
38+|>. 12|<. 12|=. 12|12|
39+|>. 123|<. 123|=. 123|123|
40+|>. 1|<. 1|=. 1|1|
6741
6842Simple table indented two spaces:
6943
@@ -164,28 +138,9 @@ Multiline table without caption:
164138
165139Table without column headers:
166140
167−<table>
168−<tbody>
169−<tr class="odd">
170−<td align="right">12</td>
171−<td align="left">12</td>
172−<td align="center">12</td>
173−<td align="right">12</td>
174−</tr>
175−<tr class="even">
176−<td align="right">123</td>
177−<td align="left">123</td>
178−<td align="center">123</td>
179−<td align="right">123</td>
180−</tr>
181−<tr class="odd">
182−<td align="right">1</td>
183−<td align="left">1</td>
184−<td align="center">1</td>
185−<td align="right">1</td>
186−</tr>
187−</tbody>
188−</table>
141+|>. 12|<. 12|=. 12|>. 12|
142+|>. 123|<. 123|=. 123|>. 123|
143+|>. 1|<. 1|=. 1|>. 1|
189144
190145Multiline table without column headers:
191146