From c73ae81628b77d8b5002e8216650dd8b449768b5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 24 Nov 2015 17:20:15 -0800 Subject: LaTeX reader: Improved smart quote parsing. This fixes redering of unmatched quotes. Closes #2555. --- src/Text/Pandoc/Readers/LaTeX.hs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 241ac145a..6500cb29f 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -166,26 +166,25 @@ mathChars = (concat <$>) $ quoted' :: (Inlines -> Inlines) -> LP String -> LP () -> LP Inlines quoted' f starter ender = do - smart <- getOption readerSmart startchs <- starter - ((f . mconcat) <$> manyTill inline ender) <|> - lit (if smart - then case startchs of + smart <- getOption readerSmart + if smart + then do + ils <- many (notFollowedBy ender >> inline) + (ender >> return (f (mconcat ils))) <|> + lit (case startchs of "``" -> "“" "`" -> "‘" - _ -> startchs - else startchs) + _ -> startchs) + else lit startchs doubleQuote :: LP Inlines doubleQuote = do - smart <- getOption readerSmart - if smart - then quoted' doubleQuoted (try $ string "``") (void $ try $ string "''") - <|> quoted' doubleQuoted (string "“") (void $ char '”') - -- the following is used by babel for localized quotes: - <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'") - <|> quoted' doubleQuoted (string "\"") (void $ char '"') - else str <$> many1 (oneOf "`'“”\"") + quoted' doubleQuoted (try $ string "``") (void $ try $ string "''") + <|> quoted' doubleQuoted (string "“") (void $ char '”') + -- the following is used by babel for localized quotes: + <|> quoted' doubleQuoted (try $ string "\"`") (void $ try $ string "\"'") + <|> quoted' doubleQuoted (string "\"") (void $ char '"') singleQuote :: LP Inlines singleQuote = do -- cgit v1.2.3