From b92b8e8a3da929ff0c96cef6c085d21016ac1851 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 13 Jan 2013 11:29:00 -0800 Subject: RST reader: Refactored line block parser. --- src/Text/Pandoc/Readers/RST.hs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/Text/Pandoc/Readers/RST.hs') diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 5f6850148..619f0ecff 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -201,27 +201,23 @@ fieldList = try $ do -- line block -- -lineBlockLine :: RSTParser Inlines +lineBlockLine :: RSTParser String lineBlockLine = try $ do char '|' - char ' ' <|> lookAhead (char '\n') - white <- many spaceChar - line <- many1 $ (notFollowedBy newline >> inline) <|> (try $ endline >>~ char ' ') - optional endline - return $ if null white - then mconcat line - else B.str (spToNbsp white) <> mconcat line - -spToNbsp :: String -> String -spToNbsp (' ':xs) = '\160' : spToNbsp xs -spToNbsp (x:xs) = x : spToNbsp xs -spToNbsp [] = "" + char ' ' + white <- many (spaceChar >> return '\160') + notFollowedBy newline + line <- anyLine + continuations <- many (try $ char ' ' >> anyLine) + return $ white ++ unwords (line : continuations) lineBlock :: RSTParser Blocks lineBlock = try $ do lines' <- many1 lineBlockLine + lines'' <- mapM (parseFromString + (trimInlines . mconcat <$> many inline)) lines' skipMany1 $ blankline <|> try (char '|' >> blankline) - return $ B.para (mconcat $ intersperse B.linebreak lines') + return $ B.para (mconcat $ intersperse B.linebreak lines'') -- -- paragraph block -- cgit v1.2.3