LaTeX reader: Parse contents of curly quotes or matched " as quotes.

This commit is contained in:
John MacFarlane
2013-11-18 20:28:27 -08:00
parent e690c87dc4
commit a3eba6ee84
2 changed files with 18 additions and 8 deletions
+17 -7
View File
@@ -163,13 +163,23 @@ mathChars = concat <$>
<|> (\c -> ['\\',c]) <$> (try $ char '\\' *> anyChar)
)
quoted' :: (Inlines -> Inlines) -> LP String -> LP () -> LP Inlines
quoted' f starter ender = do
startchs <- starter
try ((f . mconcat) <$> manyTill inline ender) <|> lit startchs
double_quote :: LP Inlines
double_quote = (doubleQuoted . mconcat) <$>
(try $ string "``" *> manyTill inline (try $ string "''"))
double_quote =
( quoted' doubleQuoted (try $ string "``") (void $ try $ string "''")
<|> quoted' doubleQuoted (string "") (void $ char '”')
<|> quoted' doubleQuoted (string "\"") (void $ char '"')
)
single_quote :: LP Inlines
single_quote = (singleQuoted . mconcat) <$>
(try $ char '`' *> manyTill inline (try $ char '\'' >> notFollowedBy letter))
single_quote =
( quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter)
<|> quoted' singleQuoted (string "") (try $ char '' >> notFollowedBy letter)
)
inline :: LP Inlines
inline = (mempty <$ comment)
@@ -181,10 +191,10 @@ inline = (mempty <$ comment)
((char '-') *> option (str "") (str "" <$ char '-')))
<|> double_quote
<|> single_quote
<|> (str "" <$ try (string "``")) -- nb. {``} won't be caught by double_quote
<|> (str "" <$ try (string "''"))
<|> (str "" <$ char '`') -- nb. {`} won't be caught by single_quote
<|> (str "" <$ char '')
<|> (str "" <$ char '\'')
<|> (str "" <$ char '')
<|> (str "\160" <$ char '~')
<|> (mathDisplay $ string "$$" *> mathChars <* string "$$")
<|> (mathInline $ char '$' *> mathChars <* char '$')
@@ -755,7 +765,7 @@ inlineText :: LP Inlines
inlineText = str <$> many1 inlineChar
inlineChar :: LP Char
inlineChar = noneOf "\\$%^_&~#{}^'`-[] \t\n"
inlineChar = noneOf "\\$%^_&~#{}^'`\"‘’“”-[] \t\n"
environment :: LP Blocks
environment = do
+1 -1
View File
@@ -302,7 +302,7 @@ Pandoc (Meta {unMeta = fromList [("authors",MetaList [MetaInlines [Str "John",Sp
,Para [Str "4",Space,Str "<",Space,Str "5."]
,Para [Str "6",Space,Str ">",Space,Str "5."]
,Para [Str "Backslash:",Space,Str "\\"]
,Para [Str "Backtick:",Space,Str "\8216"]
,Para [Str "Backtick:",Space,Str "`"]
,Para [Str "Asterisk:",Space,Str "*"]
,Para [Str "Underscore:",Space,Str "_"]
,Para [Str "Left",Space,Str "brace:",Space,Str "{"]