git.iko.soy/typeable/pandoc
on master help sign in
Initial implementation of tables in dokuwiki writer (#386)
48645a4claremacrae
src/Text/Pandoc/Writers/DokuWiki.hs+17−22
@@ -150,26 +150,21 @@ blockToDokuWiki opts (BlockQuote blocks) = do
150 contents <- blockListToDokuWiki opts blocks
150 contents <- blockListToDokuWiki opts blocks
151 return $ "<blockquote>" ++ contents ++ "</blockquote>"
151 return $ "<blockquote>" ++ contents ++ "</blockquote>"
152
152
153−blockToDokuWiki opts (Table capt aligns widths headers rows') = do
153+blockToDokuWiki opts (Table capt aligns _ headers rows') = do
154 let alignStrings = map alignmentToString aligns
154 let alignStrings = map alignmentToString aligns
155 captionDoc <- if null capt
155 captionDoc <- if null capt
156 then return ""
156 then return ""
157 else do
157 else do
158 c <- inlineListToDokuWiki opts capt
158 c <- inlineListToDokuWiki opts capt
159− return $ "<caption>" ++ c ++ "</caption>\n"
159+ return $ "" ++ c ++ "\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
165 head' <- if all null headers
160 head' <- if all null headers
166 then return ""
161 then return ""
167 else do
162 else do
168 hs <- tableRowToDokuWiki opts alignStrings 0 headers
163 hs <- tableRowToDokuWiki opts alignStrings 0 headers
169− return $ "<thead>\n" ++ hs ++ "\n</thead>\n"
164+ return $ hs ++ "\n"
170 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
165 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
171− return $ "<table>\n" ++ captionDoc ++ coltags ++ head' ++
166+ return $ captionDoc ++ head' ++
172− "<tbody>\n" ++ unlines body' ++ "</tbody>\n</table>\n"
167+ unlines body'
173
168
174blockToDokuWiki opts x@(BulletList items) = do
169blockToDokuWiki opts x@(BulletList items) = do
175 oldUseTags <- get >>= return . stUseTags
170 oldUseTags <- get >>= return . stUseTags
@@ -325,34 +320,34 @@ tableRowToDokuWiki :: WriterOptions
325 -> [[Block]]
320 -> [[Block]]
326 -> State WriterState String
321 -> State WriterState String
327tableRowToDokuWiki opts alignStrings rownum cols' = do
322tableRowToDokuWiki opts alignStrings rownum cols' = do
328− let celltype = if rownum == 0 then "th" else "td"
323+ let celltype = if rownum == 0 then "" else ""
329− let rowclass = case rownum of
330− 0 -> "header"
331− x | x `rem` 2 == 1 -> "odd"
332− _ -> "even"
333 cols'' <- sequence $ zipWith
324 cols'' <- sequence $ zipWith
334 (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
325 (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
335 alignStrings cols'
326 alignStrings cols'
336− return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
327+ return $ "| " ++ "" ++ joinColumns cols'' ++ " |"
337
328
338alignmentToString :: Alignment -> [Char]
329alignmentToString :: Alignment -> [Char]
339alignmentToString alignment = case alignment of
330alignmentToString alignment = case alignment of
340− AlignLeft -> "left"
331+ AlignLeft -> ""
341− AlignRight -> "right"
332+ AlignRight -> ""
342− AlignCenter -> "center"
333+ AlignCenter -> ""
343− AlignDefault -> "left"
334+ AlignDefault -> ""
344
335
345tableItemToDokuWiki :: WriterOptions
336tableItemToDokuWiki :: WriterOptions
346 -> String
337 -> String
347 -> String
338 -> String
348 -> [Block]
339 -> [Block]
349 -> State WriterState String
340 -> State WriterState String
341+-- TODO Fix celltype and align' defined but not used
350tableItemToDokuWiki opts celltype align' item = do
342tableItemToDokuWiki opts celltype align' item = do
351− let mkcell x = "<" ++ celltype ++ " align=\"" ++ align' ++ "\">" ++
343+ let mkcell x = "" ++ x ++ ""
352− x ++ "</" ++ celltype ++ ">"
353 contents <- blockListToDokuWiki opts item
344 contents <- blockListToDokuWiki opts item
354 return $ mkcell contents
345 return $ mkcell contents
355
346
347+-- | Concatenates columns together.
348+joinColumns :: [String] -> String
349+joinColumns = intercalate " | "
350+
356-- | Convert list of Pandoc block elements to DokuWiki.
351-- | Convert list of Pandoc block elements to DokuWiki.
357blockListToDokuWiki :: WriterOptions -- ^ Options
352blockListToDokuWiki :: WriterOptions -- ^ Options
358 -> [Block] -- ^ List of block elements
353 -> [Block] -- ^ List of block elements
tests/tables.dokuwiki+26−191
@@ -1,212 +1,47 @@
1Simple table with caption:
1Simple table with caption:
2
2
3−<table>
4−<caption>Demonstration of simple table syntax.</caption>
3+Demonstration of simple table syntax.
5−<thead>
4+| Right | Left | Center | Default |
6−<tr class="header">
5+| 12 | 12 | 12 | 12 |
7−<th align="right">Right</th>
6+| 123 | 123 | 123 | 123 |
8−<th align="left">Left</th>
7+| 1 | 1 | 1 | 1 |
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>
34
8
35Simple table without caption:
9Simple table without caption:
36
10
37−<table>
11+| Right | Left | Center | Default |
38−<thead>
12+| 12 | 12 | 12 | 12 |
39−<tr class="header">
13+| 123 | 123 | 123 | 123 |
40−<th align="right">Right</th>
14+| 1 | 1 | 1 | 1 |
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>
67
15
68Simple table indented two spaces:
16Simple table indented two spaces:
69
17
70−<table>
71−<caption>Demonstration of simple table syntax.</caption>
18+Demonstration of simple table syntax.
72−<thead>
19+| Right | Left | Center | Default |
73−<tr class="header">
20+| 12 | 12 | 12 | 12 |
74−<th align="right">Right</th>
21+| 123 | 123 | 123 | 123 |
75−<th align="left">Left</th>
22+| 1 | 1 | 1 | 1 |
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>
101
23
102Multiline table with caption:
24Multiline table with caption:
103
25
104−<table>
105−<caption>Here's the caption. It may span multiple lines.</caption>
26+Here's the caption. It may span multiple lines.
106−<col width="15%" />
27+| Centered Header | Left Aligned | Right Aligned | Default aligned |
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>
28+| First | row | 12.0 | Example of a row that spans multiple lines. |
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>
29+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
130−</tr>
131−</tbody>
132−</table>
133
30
134Multiline table without caption:
31Multiline table without caption:
135
32
136−<table>
33+| Centered Header | Left Aligned | Right Aligned | Default aligned |
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>
34+| First | row | 12.0 | Example of a row that spans multiple lines. |
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>
35+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
161−</tr>
162−</tbody>
163−</table>
164
36
165Table without column headers:
37Table without column headers:
166
38
167−<table>
39+| 12 | 12 | 12 | 12 |
168−<tbody>
40+| 123 | 123 | 123 | 123 |
169−<tr class="odd">
41+| 1 | 1 | 1 | 1 |
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>
189
42
190Multiline table without column headers:
43Multiline table without column headers:
191
44
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>
45+| First | row | 12.0 | Example of a row that spans multiple lines. |
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>
46+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
209−</tr>
210−</tbody>
211−</table>
212
47