From 4d25bba5f7a620ee6fe43c43d1a14cce4c357858 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 2 Mar 2017 16:48:53 +0100 Subject: RST reader: Handle multiline cells in simple tables. Closes #1166. --- src/Text/Pandoc/Readers/RST.hs | 24 ++++++++++++++------- test/command/1166.md | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 test/command/1166.md diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index fbba022fa..d3e253da8 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -1029,22 +1029,29 @@ simpleTableFooter = try $ simpleTableSep '=' >> blanklines -- Parse a raw line and split it into chunks by indices. simpleTableRawLine :: Monad m => [Int] -> RSTParser m [String] -simpleTableRawLine indices = do - line <- many1Till anyChar newline - return (simpleTableSplitLine indices line) +simpleTableRawLine indices = simpleTableSplitLine indices <$> anyLine + +simpleTableRawLineWithEmptyCell :: Monad m => [Int] -> RSTParser m [String] +simpleTableRawLineWithEmptyCell indices = try $ do + cs <- simpleTableRawLine indices + let isEmptyCell = all (\c -> c == ' ' || c == '\t') + guard $ any isEmptyCell cs + return cs -- Parse a table row and return a list of blocks (columns). simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks] simpleTableRow indices = do notFollowedBy' simpleTableFooter firstLine <- simpleTableRawLine indices - colLines <- return [] -- TODO - let cols = map unlines . transpose $ firstLine : colLines - mapM (parseFromString (mconcat <$> many plain)) cols + conLines <- many $ simpleTableRawLineWithEmptyCell indices + let cols = map unlines . transpose $ firstLine : conLines ++ + [replicate (length indices) "" + | not (null conLines)] + mapM (parseFromString parseBlocks) cols simpleTableSplitLine :: [Int] -> String -> [String] simpleTableSplitLine indices line = - map trim + map trimr $ tail $ splitByIndices (init indices) line simpleTableHeader :: PandocMonad m @@ -1125,7 +1132,8 @@ hyphens = do escapedChar :: Monad m => ParserT [Char] st m Inlines escapedChar = do c <- escaped anyChar - return $ if c == ' ' -- '\ ' is null in RST + return $ if c == ' ' || c == '\n' || c == '\r' + -- '\ ' is null in RST then mempty else B.str [c] diff --git a/test/command/1166.md b/test/command/1166.md new file mode 100644 index 000000000..756a065db --- /dev/null +++ b/test/command/1166.md @@ -0,0 +1,48 @@ +See #1166 and . + +``` +% pandoc -f rst -t html5 +===== ===== +col 1 col 2 +===== ===== +1 Second column of row 1. +2 Second column of row 2. + Second line of paragraph. +3 - Second column of row 3. + + - Second item in bullet + list (row 3, column 2). +\ Row 4; column 1 will be empty. +===== ===== +^D + + + + + + + + + + + + + + + + + + + + + + + + + +
col 1col 2
1Second column of row 1.

2

Second column of row 2. Second line of paragraph.

3

    +
  • Second column of row 3.
  • +
  • Second item in bullet list (row 3, column 2).
  • +
Row 4; column 1 will be empty.
+``` + -- cgit v1.2.3