From eb4fe5e82c65b5dc2f5689e4b1bceff0179397b5 Mon Sep 17 00:00:00 2001 From: claremacrae Date: Sat, 17 Aug 2013 08:48:29 +0100 Subject: Implement table headings in dokuwiki writer (#386) --- src/Text/Pandoc/Writers/DokuWiki.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc/Writers') 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: [ ] Implement definition lists [ ] Don't generate lists using
    and
      [ ] Don't generate
      - [ ] 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 -- cgit v1.2.3