@@ -32,7 +32,7 @@ DokuWiki: <https://www.dokuwiki.org/dokuwiki>
3232
3333{-
3434 [ ] Implement nested blockquotes (currently only ever does one level)
35− [ ] Implement alignment of text in tables
35+ [x] Implement alignment of text in tables
3636 [ ] Implement comments
3737 [ ] Work through the Dokuwiki spec, and check I've not missed anything out
3838 [ ] Remove dud/duplicate code
@@ -182,7 +182,6 @@ blockToDokuWiki opts (BlockQuote blocks) = do
182182 else return $ "<HTML><blockquote>\n" ++ contents ++ "</blockquote></HTML>"
183183
184184blockToDokuWiki opts (Table capt aligns _ headers rows') = do
185− let alignStrings = map alignmentToString aligns
186185 captionDoc <- if null capt
187186 then return ""
188187 else do
@@ -191,9 +190,9 @@ blockToDokuWiki opts (Table capt aligns _ headers rows') = do
191190 head' <- if all null headers
192191 then return ""
193192 else do
194− hs <- tableHeaderToDokuWiki opts alignStrings 0 headers
193+ hs <- tableHeaderToDokuWiki opts aligns headers
195194 return $ hs ++ "\n"
196− body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
195+ body' <- mapM (tableRowToDokuWiki opts aligns) rows'
197196 return $ captionDoc ++ head' ++
198197 unlines body'
199198
@@ -360,44 +359,37 @@ backSlashLineBreaks cs = reverse $ g $ reverse $ concatMap f cs
360359
361360-- TODO Eliminate copy-and-pasted code in tableHeaderToDokuWiki and tableRowToDokuWiki
362361tableHeaderToDokuWiki :: WriterOptions
363− -> [String]
364− -> Int
362+ -> [Alignment]
365363 -> [[Block]]
366364 -> DokuWiki String
367−tableHeaderToDokuWiki opts alignStrings rownum cols' = do
368− let celltype = if rownum == 0 then "" else ""
365+tableHeaderToDokuWiki opts aligns cols' = do
369366 cols'' <- zipWithM
370− (tableItemToDokuWiki opts celltype)
371− alignStrings cols'
372− return $ "^ " ++ "" ++ joinHeaders cols'' ++ " ^"
367+ (tableItemToDokuWiki opts)
368+ aligns cols'
369+ return $ "^ " ++ joinHeaders cols'' ++ " ^"
373370
374371tableRowToDokuWiki :: WriterOptions
375− -> [String]
376− -> Int
372+ -> [Alignment]
377373 -> [[Block]]
378374 -> DokuWiki String
379−tableRowToDokuWiki opts alignStrings rownum cols' = do
380− let celltype = if rownum == 0 then "" else ""
375+tableRowToDokuWiki opts alignStrings cols' = do
381376 cols'' <- zipWithM
382− (tableItemToDokuWiki opts celltype)
377+ (tableItemToDokuWiki opts)
383378 alignStrings cols'
384379 return $ "| " ++ "" ++ joinColumns cols'' ++ " |"
385380
386−alignmentToString :: Alignment -> [Char]
387−alignmentToString alignment = case alignment of
388− AlignLeft -> ""
389− AlignRight -> ""
390− AlignCenter -> ""
391− AlignDefault -> ""
392−
393381tableItemToDokuWiki :: WriterOptions
394− -> String
395− -> String
382+ -> Alignment
396383 -> [Block]
397384 -> DokuWiki String
398385-- TODO Fix celltype and align' defined but not used
399−tableItemToDokuWiki opts _celltype _align' item = do
400− let mkcell x = "" ++ x ++ ""
386+tableItemToDokuWiki opts align' item = do
387+ let mkcell x = (if align' == AlignRight || align' == AlignCenter
388+ then " "
389+ else "") ++ x ++
390+ (if align' == AlignLeft || align' == AlignCenter
391+ then " "
392+ else "")
401393 contents <- local (\s -> s { stBackSlashLB = True }) $
402394 blockListToDokuWiki opts item
403395 return $ mkcell contents