aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaremacrae <github@cfmacrae.fastmail.co.uk>2013-08-17 08:48:29 +0100
committerclaremacrae <github@cfmacrae.fastmail.co.uk>2013-08-17 08:48:29 +0100
commiteb4fe5e82c65b5dc2f5689e4b1bceff0179397b5 (patch)
tree540a9e9dbdc385b812f2d07dba515b6fd1fa8c6b
parent48645a47555dd5c243f5d28f9c8274b368917856 (diff)
downloadpandoc-eb4fe5e82c65b5dc2f5689e4b1bceff0179397b5.tar.gz
Implement table headings in dokuwiki writer (#386)
-rw-r--r--src/Text/Pandoc/Writers/DokuWiki.hs21
-rw-r--r--tests/tables.dokuwiki10
2 files changed, 24 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/DokuWiki.hs b/src/Text/Pandoc/Writers/DokuWiki.hs
index 87145d723..76fe2fa36 100644
--- a/src/Text/Pandoc/Writers/DokuWiki.hs
+++ b/src/Text/Pandoc/Writers/DokuWiki.hs
@@ -36,7 +36,7 @@ DokuWiki: <https://www.dokuwiki.org/dokuwiki>
[ ] Implement definition lists
[ ] Don't generate lists using <ol> and <ul>
[ ] Don't generate <div>
- [ ] Implement conversion of tables
+ [ ] Implement alignment of text in tables
[ ] Implement comments
[ ] Work through the Dokuwiki spec, and check I've not missed anything out
[ ] 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
head' <- if all null headers
then return ""
else do
- hs <- tableRowToDokuWiki opts alignStrings 0 headers
+ hs <- tableHeaderToDokuWiki opts alignStrings 0 headers
return $ hs ++ "\n"
body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
return $ captionDoc ++ head' ++
@@ -314,6 +314,19 @@ vcat = intercalate "\n"
-- Auxiliary functions for tables:
+-- TODO Eliminate copy-and-pasted code in tableHeaderToDokuWiki and tableRowToDokuWiki
+tableHeaderToDokuWiki :: WriterOptions
+ -> [String]
+ -> Int
+ -> [[Block]]
+ -> State WriterState String
+tableHeaderToDokuWiki opts alignStrings rownum cols' = do
+ let celltype = if rownum == 0 then "" else ""
+ cols'' <- sequence $ zipWith
+ (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
+ alignStrings cols'
+ return $ "^ " ++ "" ++ joinHeaders cols'' ++ " ^"
+
tableRowToDokuWiki :: WriterOptions
-> [String]
-> Int
@@ -348,6 +361,10 @@ tableItemToDokuWiki opts celltype align' item = do
joinColumns :: [String] -> String
joinColumns = intercalate " | "
+-- | Concatenates headers together.
+joinHeaders :: [String] -> String
+joinHeaders = intercalate " ^ "
+
-- | Convert list of Pandoc block elements to DokuWiki.
blockListToDokuWiki :: WriterOptions -- ^ Options
-> [Block] -- ^ List of block elements
diff --git a/tests/tables.dokuwiki b/tests/tables.dokuwiki
index 0a1b0a4ff..4fcae4e6f 100644
--- a/tests/tables.dokuwiki
+++ b/tests/tables.dokuwiki
@@ -1,14 +1,14 @@
Simple table with caption:
Demonstration of simple table syntax.
-| Right | Left | Center | Default |
+^ Right ^ Left ^ Center ^ Default ^
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
Simple table without caption:
-| Right | Left | Center | Default |
+^ Right ^ Left ^ Center ^ Default ^
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
@@ -16,7 +16,7 @@ Simple table without caption:
Simple table indented two spaces:
Demonstration of simple table syntax.
-| Right | Left | Center | Default |
+^ Right ^ Left ^ Center ^ Default ^
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
@@ -24,13 +24,13 @@ Demonstration of simple table syntax.
Multiline table with caption:
Here's the caption. It may span multiple lines.
-| Centered Header | Left Aligned | Right Aligned | Default aligned |
+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
| First | row | 12.0 | Example of a row that spans multiple lines. |
| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
Multiline table without caption:
-| Centered Header | Left Aligned | Right Aligned | Default aligned |
+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
| First | row | 12.0 | Example of a row that spans multiple lines. |
| Second | row | 5.0 | Here's another one. Note the blank line between rows. |