git.iko.soy/typeable/pandoc
on master help sign in
Implement table headings in dokuwiki writer (#386)
commiteb4fe5e82c65b5dc2f5689e4b1bceff0179397b5 authorclaremacrae <github@cfmacrae.fastmail.co.uk> dateSat 17 Aug 2013, 08:48 (13 years ago) parent48645a4
2 files changed+24−7
src/Text/Pandoc/Writers/DokuWiki.hs+19−2 tests/tables.dokuwiki+5−5
src/Text/Pandoc/Writers/DokuWiki.hs+19−2
@@ -36,7 +36,7 @@ DokuWiki: <https://www.dokuwiki.org/dokuwiki>
3636 [ ] Implement definition lists
3737 [ ] Don't generate lists using <ol> and <ul>
3838 [ ] Don't generate <div>
39− [ ] Implement conversion of tables
39+ [ ] Implement alignment of text in tables
4040 [ ] Implement comments
4141 [ ] Work through the Dokuwiki spec, and check I've not missed anything out
4242 [ ] 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
160160 head' <- if all null headers
161161 then return ""
162162 else do
163− hs <- tableRowToDokuWiki opts alignStrings 0 headers
163+ hs <- tableHeaderToDokuWiki opts alignStrings 0 headers
164164 return $ hs ++ "\n"
165165 body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
166166 return $ captionDoc ++ head' ++
@@ -314,6 +314,19 @@ vcat = intercalate "\n"
314314
315315-- Auxiliary functions for tables:
316316
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+
317330tableRowToDokuWiki :: WriterOptions
318331 -> [String]
319332 -> Int
@@ -348,6 +361,10 @@ tableItemToDokuWiki opts celltype align' item = do
348361joinColumns :: [String] -> String
349362joinColumns = intercalate " | "
350363
364+-- | Concatenates headers together.
365+joinHeaders :: [String] -> String
366+joinHeaders = intercalate " ^ "
367+
351368-- | Convert list of Pandoc block elements to DokuWiki.
352369blockListToDokuWiki :: WriterOptions -- ^ Options
353370 -> [Block] -- ^ List of block elements
tests/tables.dokuwiki+5−5
@@ -1,14 +1,14 @@
11Simple table with caption:
22
33Demonstration of simple table syntax.
4−| Right | Left | Center | Default |
4+^ Right ^ Left ^ Center ^ Default ^
55| 12 | 12 | 12 | 12 |
66| 123 | 123 | 123 | 123 |
77| 1 | 1 | 1 | 1 |
88
99Simple table without caption:
1010
11−| Right | Left | Center | Default |
11+^ Right ^ Left ^ Center ^ Default ^
1212| 12 | 12 | 12 | 12 |
1313| 123 | 123 | 123 | 123 |
1414| 1 | 1 | 1 | 1 |
@@ -16,7 +16,7 @@ Simple table without caption:
1616Simple table indented two spaces:
1717
1818Demonstration of simple table syntax.
19−| Right | Left | Center | Default |
19+^ Right ^ Left ^ Center ^ Default ^
2020| 12 | 12 | 12 | 12 |
2121| 123 | 123 | 123 | 123 |
2222| 1 | 1 | 1 | 1 |
@@ -24,13 +24,13 @@ Demonstration of simple table syntax.
2424Multiline table with caption:
2525
2626Here'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 ^
2828| First | row | 12.0 | Example of a row that spans multiple lines. |
2929| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
3030
3131Multiline table without caption:
3232
33−| Centered Header | Left Aligned | Right Aligned | Default aligned |
33+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
3434| First | row | 12.0 | Example of a row that spans multiple lines. |
3535| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
3636