git.iko.soy/typeable/pandoc
on master help sign in
Initial implementation of tables in dokuwiki writer (#386)

Todo: alignment, and headings

commit48645a47555dd5c243f5d28f9c8274b368917856 authorclaremacrae <github@cfmacrae.fastmail.co.uk> dateSun 11 Aug 2013, 22:22 (13 years ago) parente5004bc
2 files changed+43−213
src/Text/Pandoc/Writers/DokuWiki.hs+17−22 tests/tables.dokuwiki+26−191
src/Text/Pandoc/Writers/DokuWiki.hs+17−22
@@ -150,26 +150,21 @@ blockToDokuWiki opts (BlockQuote blocks) = do
150150 contents <- blockListToDokuWiki opts blocks
151151 return $ "<blockquote>" ++ contents ++ "</blockquote>"
152152
153−blockToDokuWiki opts (Table capt aligns widths headers rows') = do
153+blockToDokuWiki opts (Table capt aligns _ headers rows') = do
154154 let alignStrings = map alignmentToString aligns
155155 captionDoc <- if null capt
156156 then return ""
157157 else do
158158 c <- inlineListToDokuWiki opts capt
159− return $ "<caption>" ++ c ++ "</caption>\n"
160− let percent w = show (truncate (100*w) :: Integer) ++ "%"
161− let coltags = if all (== 0.0) widths
162− then ""
163− else unlines $ map
164− (\w -> "<col width=\"" ++ percent w ++ "\" />") widths
159+ return $ "" ++ c ++ "\n"
165160 head' <- if all null headers
166161 then return ""
167162 else do
168163 hs <- tableRowToDokuWiki opts alignStrings 0 headers
169− return $ "<thead>\n" ++ hs ++ "\n</thead>\n"
164+ return $ hs ++ "\n"
170165 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
171− return $ "<table>\n" ++ captionDoc ++ coltags ++ head' ++
172− "<tbody>\n" ++ unlines body' ++ "</tbody>\n</table>\n"
166+ return $ captionDoc ++ head' ++
167+ unlines body'
173168
174169blockToDokuWiki opts x@(BulletList items) = do
175170 oldUseTags <- get >>= return . stUseTags
@@ -325,34 +320,34 @@ tableRowToDokuWiki :: WriterOptions
325320 -> [[Block]]
326321 -> State WriterState String
327322tableRowToDokuWiki opts alignStrings rownum cols' = do
328− let celltype = if rownum == 0 then "th" else "td"
329− let rowclass = case rownum of
330− 0 -> "header"
331− x | x `rem` 2 == 1 -> "odd"
332− _ -> "even"
323+ let celltype = if rownum == 0 then "" else ""
333324 cols'' <- sequence $ zipWith
334325 (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
335326 alignStrings cols'
336− return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
327+ return $ "| " ++ "" ++ joinColumns cols'' ++ " |"
337328
338329alignmentToString :: Alignment -> [Char]
339330alignmentToString alignment = case alignment of
340− AlignLeft -> "left"
341− AlignRight -> "right"
342− AlignCenter -> "center"
343− AlignDefault -> "left"
331+ AlignLeft -> ""
332+ AlignRight -> ""
333+ AlignCenter -> ""
334+ AlignDefault -> ""
344335
345336tableItemToDokuWiki :: WriterOptions
346337 -> String
347338 -> String
348339 -> [Block]
349340 -> State WriterState String
341+-- TODO Fix celltype and align' defined but not used
350342tableItemToDokuWiki opts celltype align' item = do
351− let mkcell x = "<" ++ celltype ++ " align=\"" ++ align' ++ "\">" ++
352− x ++ "</" ++ celltype ++ ">"
343+ let mkcell x = "" ++ x ++ ""
353344 contents <- blockListToDokuWiki opts item
354345 return $ mkcell contents
355346
347+-- | Concatenates columns together.
348+joinColumns :: [String] -> String
349+joinColumns = intercalate " | "
350+
356351-- | Convert list of Pandoc block elements to DokuWiki.
357352blockListToDokuWiki :: WriterOptions -- ^ Options
358353 -> [Block] -- ^ List of block elements
tests/tables.dokuwiki+26−191
@@ -1,212 +1,47 @@
11Simple table with caption:
22
3−<table>
4−<caption>Demonstration of simple table syntax.</caption>
5−<thead>
6−<tr class="header">
7−<th align="right">Right</th>
8−<th align="left">Left</th>
9−<th align="center">Center</th>
10−<th align="left">Default</th>
11−</tr>
12−</thead>
13−<tbody>
14−<tr class="odd">
15−<td align="right">12</td>
16−<td align="left">12</td>
17−<td align="center">12</td>
18−<td align="left">12</td>
19−</tr>
20−<tr class="even">
21−<td align="right">123</td>
22−<td align="left">123</td>
23−<td align="center">123</td>
24−<td align="left">123</td>
25−</tr>
26−<tr class="odd">
27−<td align="right">1</td>
28−<td align="left">1</td>
29−<td align="center">1</td>
30−<td align="left">1</td>
31−</tr>
32−</tbody>
33−</table>
3+Demonstration of simple table syntax.
4+| Right | Left | Center | Default |
5+| 12 | 12 | 12 | 12 |
6+| 123 | 123 | 123 | 123 |
7+| 1 | 1 | 1 | 1 |
348
359Simple table without caption:
3610
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>
11+| Right | Left | Center | Default |
12+| 12 | 12 | 12 | 12 |
13+| 123 | 123 | 123 | 123 |
14+| 1 | 1 | 1 | 1 |
6715
6816Simple table indented two spaces:
6917
70−<table>
71−<caption>Demonstration of simple table syntax.</caption>
72−<thead>
73−<tr class="header">
74−<th align="right">Right</th>
75−<th align="left">Left</th>
76−<th align="center">Center</th>
77−<th align="left">Default</th>
78−</tr>
79−</thead>
80−<tbody>
81−<tr class="odd">
82−<td align="right">12</td>
83−<td align="left">12</td>
84−<td align="center">12</td>
85−<td align="left">12</td>
86−</tr>
87−<tr class="even">
88−<td align="right">123</td>
89−<td align="left">123</td>
90−<td align="center">123</td>
91−<td align="left">123</td>
92−</tr>
93−<tr class="odd">
94−<td align="right">1</td>
95−<td align="left">1</td>
96−<td align="center">1</td>
97−<td align="left">1</td>
98−</tr>
99−</tbody>
100−</table>
18+Demonstration of simple table syntax.
19+| Right | Left | Center | Default |
20+| 12 | 12 | 12 | 12 |
21+| 123 | 123 | 123 | 123 |
22+| 1 | 1 | 1 | 1 |
10123
10224Multiline table with caption:
10325
104−<table>
105−<caption>Here's the caption. It may span multiple lines.</caption>
106−<col width="15%" />
107−<col width="13%" />
108−<col width="16%" />
109−<col width="33%" />
110−<thead>
111−<tr class="header">
112−<th align="center">Centered Header</th>
113−<th align="left">Left Aligned</th>
114−<th align="right">Right Aligned</th>
115−<th align="left">Default aligned</th>
116−</tr>
117−</thead>
118−<tbody>
119−<tr class="odd">
120−<td align="center">First</td>
121−<td align="left">row</td>
122−<td align="right">12.0</td>
123−<td align="left">Example of a row that spans multiple lines.</td>
124−</tr>
125−<tr class="even">
126−<td align="center">Second</td>
127−<td align="left">row</td>
128−<td align="right">5.0</td>
129−<td align="left">Here's another one. Note the blank line between rows.</td>
130−</tr>
131−</tbody>
132−</table>
26+Here's the caption. It may span multiple lines.
27+| Centered Header | Left Aligned | Right Aligned | Default aligned |
28+| First | row | 12.0 | Example of a row that spans multiple lines. |
29+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
13330
13431Multiline table without caption:
13532
136−<table>
137−<col width="15%" />
138−<col width="13%" />
139−<col width="16%" />
140−<col width="33%" />
141−<thead>
142−<tr class="header">
143−<th align="center">Centered Header</th>
144−<th align="left">Left Aligned</th>
145−<th align="right">Right Aligned</th>
146−<th align="left">Default aligned</th>
147−</tr>
148−</thead>
149−<tbody>
150−<tr class="odd">
151−<td align="center">First</td>
152−<td align="left">row</td>
153−<td align="right">12.0</td>
154−<td align="left">Example of a row that spans multiple lines.</td>
155−</tr>
156−<tr class="even">
157−<td align="center">Second</td>
158−<td align="left">row</td>
159−<td align="right">5.0</td>
160−<td align="left">Here's another one. Note the blank line between rows.</td>
161−</tr>
162−</tbody>
163−</table>
33+| Centered Header | Left Aligned | Right Aligned | Default aligned |
34+| First | row | 12.0 | Example of a row that spans multiple lines. |
35+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
16436
16537Table without column headers:
16638
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>
39+| 12 | 12 | 12 | 12 |
40+| 123 | 123 | 123 | 123 |
41+| 1 | 1 | 1 | 1 |
18942
19043Multiline table without column headers:
19144
192−<table>
193−<col width="15%" />
194−<col width="13%" />
195−<col width="16%" />
196−<col width="33%" />
197−<tbody>
198−<tr class="odd">
199−<td align="center">First</td>
200−<td align="left">row</td>
201−<td align="right">12.0</td>
202−<td align="left">Example of a row that spans multiple lines.</td>
203−</tr>
204−<tr class="even">
205−<td align="center">Second</td>
206−<td align="left">row</td>
207−<td align="right">5.0</td>
208−<td align="left">Here's another one. Note the blank line between rows.</td>
209−</tr>
210−</tbody>
211−</table>
45+| First | row | 12.0 | Example of a row that spans multiple lines. |
46+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
21247