From a8273009baeeece65b60816e1eb42ae54b977f8d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 30 Aug 2014 20:34:42 -0700 Subject: Textile reader: Improved table support. We can now handle all different alignment types, for simple tables only (no captions, no relative widths, cell contents just plain inlines). Other tables are still handled using raw HTML. Addresses #1585 as far as it can be addresssed, I believe. --- src/Text/Pandoc/Writers/Textile.hs | 17 ++++++++--- tests/tables.textile | 59 +++++--------------------------------- 2 files changed, 20 insertions(+), 56 deletions(-) diff --git a/src/Text/Pandoc/Writers/Textile.hs b/src/Text/Pandoc/Writers/Textile.hs index 20cb5f6f7..05eb50349 100644 --- a/src/Text/Pandoc/Writers/Textile.hs +++ b/src/Text/Pandoc/Writers/Textile.hs @@ -39,6 +39,7 @@ import Text.Pandoc.Templates (renderTemplate') import Text.Pandoc.XML ( escapeStringForXML ) import Data.List ( intercalate ) import Control.Monad.State +import Control.Applicative ((<$>)) import Data.Char ( isSpace ) data WriterState = WriterState { @@ -164,14 +165,22 @@ blockToTextile opts (BlockQuote blocks) = do return $ "
\n\n" ++ contents ++ "\n
\n" blockToTextile opts (Table [] aligns widths headers rows') | - all (==0) widths && all (`elem` [AlignLeft,AlignDefault]) aligns = do + all (==0) widths = do hs <- mapM (liftM (("_. " ++) . stripTrailingNewlines) . blockListToTextile opts) headers let cellsToRow cells = "|" ++ intercalate "|" cells ++ "|" - let header = if all null headers then "" else cellsToRow hs - let rowToCells = mapM (liftM stripTrailingNewlines . blockListToTextile opts) + let header = if all null headers then "" else cellsToRow hs ++ "\n" + let blocksToCell (align, bs) = do + contents <- stripTrailingNewlines <$> blockListToTextile opts bs + let alignMarker = case align of + AlignLeft -> "<. " + AlignRight -> ">. " + AlignCenter -> "=. " + AlignDefault -> "" + return $ alignMarker ++ contents + let rowToCells = mapM blocksToCell . zip aligns bs <- mapM rowToCells rows' let body = unlines $ map cellsToRow bs - return $ header ++ "\n" ++ body ++ "\n" + return $ header ++ body blockToTextile opts (Table capt aligns widths headers rows') = do let alignStrings = map alignmentToString aligns diff --git a/tests/tables.textile b/tests/tables.textile index 4836ecd79..6c6b234e6 100644 --- a/tests/tables.textile +++ b/tests/tables.textile @@ -34,36 +34,10 @@ Simple table with caption: 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: @@ -164,28 +138,9 @@ Multiline table without caption: Table without column headers: - - - - - - - - - - - - - - - - - - - - - -
12121212
123123123123
1111
+|>. 12|<. 12|=. 12|>. 12| +|>. 123|<. 123|=. 123|>. 123| +|>. 1|<. 1|=. 1|>. 1| Multiline table without column headers: -- cgit v1.2.3