From 48645a47555dd5c243f5d28f9c8274b368917856 Mon Sep 17 00:00:00 2001 From: claremacrae Date: Sun, 11 Aug 2013 22:22:07 +0100 Subject: [PATCH] Initial implementation of tables in dokuwiki writer (#386) Todo: alignment, and headings --- src/Text/Pandoc/Writers/DokuWiki.hs | 39 +++-- tests/tables.dokuwiki | 217 ++++------------------------ 2 files changed, 43 insertions(+), 213 deletions(-) diff --git a/src/Text/Pandoc/Writers/DokuWiki.hs b/src/Text/Pandoc/Writers/DokuWiki.hs index db02bde89..87145d723 100644 --- a/src/Text/Pandoc/Writers/DokuWiki.hs +++ b/src/Text/Pandoc/Writers/DokuWiki.hs @@ -150,26 +150,21 @@ blockToDokuWiki opts (BlockQuote blocks) = do contents <- blockListToDokuWiki opts blocks return $ "
" ++ contents ++ "
" -blockToDokuWiki opts (Table capt aligns widths headers rows') = do +blockToDokuWiki opts (Table capt aligns _ headers rows') = do let alignStrings = map alignmentToString aligns captionDoc <- if null capt then return "" else do c <- inlineListToDokuWiki opts capt - return $ "" ++ c ++ "\n" - let percent w = show (truncate (100*w) :: Integer) ++ "%" - let coltags = if all (== 0.0) widths - then "" - else unlines $ map - (\w -> "") widths + return $ "" ++ c ++ "\n" head' <- if all null headers then return "" else do hs <- tableRowToDokuWiki opts alignStrings 0 headers - return $ "\n" ++ hs ++ "\n\n" + return $ hs ++ "\n" body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows' - return $ "\n" ++ captionDoc ++ coltags ++ head' ++ - "\n" ++ unlines body' ++ "\n
\n" + return $ captionDoc ++ head' ++ + unlines body' blockToDokuWiki opts x@(BulletList items) = do oldUseTags <- get >>= return . stUseTags @@ -325,34 +320,34 @@ tableRowToDokuWiki :: WriterOptions -> [[Block]] -> State WriterState String tableRowToDokuWiki opts alignStrings rownum cols' = do - let celltype = if rownum == 0 then "th" else "td" - let rowclass = case rownum of - 0 -> "header" - x | x `rem` 2 == 1 -> "odd" - _ -> "even" + let celltype = if rownum == 0 then "" else "" cols'' <- sequence $ zipWith (\alignment item -> tableItemToDokuWiki opts celltype alignment item) alignStrings cols' - return $ "\n" ++ unlines cols'' ++ "" + return $ "| " ++ "" ++ joinColumns cols'' ++ " |" alignmentToString :: Alignment -> [Char] alignmentToString alignment = case alignment of - AlignLeft -> "left" - AlignRight -> "right" - AlignCenter -> "center" - AlignDefault -> "left" + AlignLeft -> "" + AlignRight -> "" + AlignCenter -> "" + AlignDefault -> "" tableItemToDokuWiki :: WriterOptions -> String -> String -> [Block] -> State WriterState String +-- TODO Fix celltype and align' defined but not used tableItemToDokuWiki opts celltype align' item = do - let mkcell x = "<" ++ celltype ++ " align=\"" ++ align' ++ "\">" ++ - x ++ "" + let mkcell x = "" ++ x ++ "" contents <- blockListToDokuWiki opts item return $ mkcell contents +-- | Concatenates columns together. +joinColumns :: [String] -> String +joinColumns = 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 4836ecd79..0a1b0a4ff 100644 --- a/tests/tables.dokuwiki +++ b/tests/tables.dokuwiki @@ -1,212 +1,47 @@ Simple table with caption: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Demonstration of simple table syntax.
RightLeftCenterDefault
12121212
123123123123
1111
+Demonstration of simple table syntax. +| Right | Left | Center | Default | +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | Simple table without caption: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RightLeftCenterDefault
12121212
123123123123
1111
+| Right | Left | Center | Default | +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | Simple table indented two spaces: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Demonstration of simple table syntax.
RightLeftCenterDefault
12121212
123123123123
1111
+Demonstration of simple table syntax. +| Right | Left | Center | Default | +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | Multiline table with caption: - - ----- - - - - - - - - - - - - - - - - - - - - - -
Here's the caption. It may span multiple lines.
Centered HeaderLeft AlignedRight AlignedDefault aligned
Firstrow12.0Example of a row that spans multiple lines.
Secondrow5.0Here's another one. Note the blank line between rows.
+Here's the caption. It may span multiple lines. +| 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 HeaderLeft AlignedRight AlignedDefault aligned
Firstrow12.0Example of a row that spans multiple lines.
Secondrow5.0Here's another one. Note the blank line between rows.
+| 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. | Table without column headers: - - - - - - - - - - - - - - - - - - - - - -
12121212
123123123123
1111
+| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | Multiline table without column headers: - ----- - - - - - - - - - - - - - -
Firstrow12.0Example of a row that spans multiple lines.
Secondrow5.0Here's another one. Note the blank line between rows.
+| 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. |