git.iko.soy/typeable/pandoc
on master help sign in
Implement table headings in dokuwiki writer (#386)
eb4fe5eclaremacrae
src/Text/Pandoc/Writers/DokuWiki.hs+19−2
@@ -36,7 +36,7 @@ DokuWiki: <https://www.dokuwiki.org/dokuwiki>
36 [ ] Implement definition lists
36 [ ] Implement definition lists
37 [ ] Don't generate lists using <ol> and <ul>
37 [ ] Don't generate lists using <ol> and <ul>
38 [ ] Don't generate <div>
38 [ ] Don't generate <div>
39− [ ] Implement conversion of tables
39+ [ ] Implement alignment of text in tables
40 [ ] Implement comments
40 [ ] Implement comments
41 [ ] Work through the Dokuwiki spec, and check I've not missed anything out
41 [ ] Work through the Dokuwiki spec, and check I've not missed anything out
42 [ ] Test the output in Dokuwiki - and compare against the display of another format, e.g. HTML
42 [ ] Test the output in Dokuwiki - and compare against the display of another format, e.g. HTML
@@ -160,7 +160,7 @@ blockToDokuWiki opts (Table capt aligns _ headers rows') = do
160 head' <- if all null headers
160 head' <- if all null headers
161 then return ""
161 then return ""
162 else do
162 else do
163− hs <- tableRowToDokuWiki opts alignStrings 0 headers
163+ hs <- tableHeaderToDokuWiki opts alignStrings 0 headers
164 return $ hs ++ "\n"
164 return $ hs ++ "\n"
165 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
165 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
166 return $ captionDoc ++ head' ++
166 return $ captionDoc ++ head' ++
@@ -314,6 +314,19 @@ vcat = intercalate "\n"
314
314
315-- Auxiliary functions for tables:
315-- Auxiliary functions for tables:
316
316
317+-- TODO Eliminate copy-and-pasted code in tableHeaderToDokuWiki and tableRowToDokuWiki
318+tableHeaderToDokuWiki :: WriterOptions
319+ -> [String]
320+ -> Int
321+ -> [[Block]]
322+ -> State WriterState String
323+tableHeaderToDokuWiki opts alignStrings rownum cols' = do
324+ let celltype = if rownum == 0 then "" else ""
325+ cols'' <- sequence $ zipWith
326+ (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
327+ alignStrings cols'
328+ return $ "^ " ++ "" ++ joinHeaders cols'' ++ " ^"
329+
317tableRowToDokuWiki :: WriterOptions
330tableRowToDokuWiki :: WriterOptions
318 -> [String]
331 -> [String]
319 -> Int
332 -> Int
@@ -348,6 +361,10 @@ tableItemToDokuWiki opts celltype align' item = do
348joinColumns :: [String] -> String
361joinColumns :: [String] -> String
349joinColumns = intercalate " | "
362joinColumns = intercalate " | "
350
363
364+-- | Concatenates headers together.
365+joinHeaders :: [String] -> String
366+joinHeaders = intercalate " ^ "
367+
351-- | Convert list of Pandoc block elements to DokuWiki.
368-- | Convert list of Pandoc block elements to DokuWiki.
352blockListToDokuWiki :: WriterOptions -- ^ Options
369blockListToDokuWiki :: WriterOptions -- ^ Options
353 -> [Block] -- ^ List of block elements
370 -> [Block] -- ^ List of block elements
tests/tables.dokuwiki+5−5
@@ -1,14 +1,14 @@
1Simple table with caption:
1Simple table with caption:
2
2
3Demonstration of simple table syntax.
3Demonstration of simple table syntax.
4−| Right | Left | Center | Default |
4+^ Right ^ Left ^ Center ^ Default ^
5| 12 | 12 | 12 | 12 |
5| 12 | 12 | 12 | 12 |
6| 123 | 123 | 123 | 123 |
6| 123 | 123 | 123 | 123 |
7| 1 | 1 | 1 | 1 |
7| 1 | 1 | 1 | 1 |
8
8
9Simple table without caption:
9Simple table without caption:
10
10
11−| Right | Left | Center | Default |
11+^ Right ^ Left ^ Center ^ Default ^
12| 12 | 12 | 12 | 12 |
12| 12 | 12 | 12 | 12 |
13| 123 | 123 | 123 | 123 |
13| 123 | 123 | 123 | 123 |
14| 1 | 1 | 1 | 1 |
14| 1 | 1 | 1 | 1 |
@@ -16,7 +16,7 @@ Simple table without caption:
16Simple table indented two spaces:
16Simple table indented two spaces:
17
17
18Demonstration of simple table syntax.
18Demonstration of simple table syntax.
19−| Right | Left | Center | Default |
19+^ Right ^ Left ^ Center ^ Default ^
20| 12 | 12 | 12 | 12 |
20| 12 | 12 | 12 | 12 |
21| 123 | 123 | 123 | 123 |
21| 123 | 123 | 123 | 123 |
22| 1 | 1 | 1 | 1 |
22| 1 | 1 | 1 | 1 |
@@ -24,13 +24,13 @@ Demonstration of simple table syntax.
24Multiline table with caption:
24Multiline table with caption:
25
25
26Here's the caption. It may span multiple lines.
26Here's the caption. It may span multiple lines.
27−| Centered Header | Left Aligned | Right Aligned | Default aligned |
27+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
28| First | row | 12.0 | Example of a row that spans multiple lines. |
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. |
29| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
30
30
31Multiline table without caption:
31Multiline table without caption:
32
32
33−| Centered Header | Left Aligned | Right Aligned | Default aligned |
33+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
34| First | row | 12.0 | Example of a row that spans multiple lines. |
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. |
35| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
36
36