git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Parse contents of curly quotes or matched `"` as quotes.
commita3eba6ee848497f98f72aef5dad112c49bdd4fec authorJohn MacFarlane <jgm@berkeley.edu> dateMon 18 Nov 2013, 20:28 (13 years ago) parente690c87
2 files changed+18−8
src/Text/Pandoc/Readers/LaTeX.hs+17−7 tests/latex-reader.native+1−1
src/Text/Pandoc/Readers/LaTeX.hs+17−7
@@ -163,13 +163,23 @@ mathChars = concat <$>
163163 <|> (\c -> ['\\',c]) <$> (try $ char '\\' *> anyChar)
164164 )
165165
166+quoted' :: (Inlines -> Inlines) -> LP String -> LP () -> LP Inlines
167+quoted' f starter ender = do
168+ startchs <- starter
169+ try ((f . mconcat) <$> manyTill inline ender) <|> lit startchs
170+
166171double_quote :: LP Inlines
167−double_quote = (doubleQuoted . mconcat) <$>
168− (try $ string "``" *> manyTill inline (try $ string "''"))
172+double_quote =
173+ ( quoted' doubleQuoted (try $ string "``") (void $ try $ string "''")
174+ <|> quoted' doubleQuoted (string "“") (void $ char '”')
175+ <|> quoted' doubleQuoted (string "\"") (void $ char '"')
176+ )
169177
170178single_quote :: LP Inlines
171−single_quote = (singleQuoted . mconcat) <$>
172− (try $ char '`' *> manyTill inline (try $ char '\'' >> notFollowedBy letter))
179+single_quote =
180+ ( quoted' singleQuoted (string "`") (try $ char '\'' >> notFollowedBy letter)
181+ <|> quoted' singleQuoted (string "‘") (try $ char '’' >> notFollowedBy letter)
182+ )
173183
174184inline :: LP Inlines
175185inline = (mempty <$ comment)
@@ -181,10 +191,10 @@ inline = (mempty <$ comment)
181191 ((char '-') *> option (str "–") (str "—" <$ char '-')))
182192 <|> double_quote
183193 <|> single_quote
184− <|> (str "“" <$ try (string "``")) -- nb. {``} won't be caught by double_quote
185194 <|> (str "”" <$ try (string "''"))
186− <|> (str "‘" <$ char '`') -- nb. {`} won't be caught by single_quote
195+ <|> (str "”" <$ char '”')
187196 <|> (str "’" <$ char '\'')
197+ <|> (str "’" <$ char '’')
188198 <|> (str "\160" <$ char '~')
189199 <|> (mathDisplay $ string "$$" *> mathChars <* string "$$")
190200 <|> (mathInline $ char '$' *> mathChars <* char '$')
@@ -755,7 +765,7 @@ inlineText :: LP Inlines
755765inlineText = str <$> many1 inlineChar
756766
757767inlineChar :: LP Char
758−inlineChar = noneOf "\\$%^_&~#{}^'`-[] \t\n"
768+inlineChar = noneOf "\\$%^_&~#{}^'`\"‘’“”-[] \t\n"
759769
760770environment :: LP Blocks
761771environment = do
tests/latex-reader.native+1−1
@@ -302,7 +302,7 @@ Pandoc (Meta {unMeta = fromList [("authors",MetaList [MetaInlines [Str "John",Sp
302302,Para [Str "4",Space,Str "<",Space,Str "5."]
303303,Para [Str "6",Space,Str ">",Space,Str "5."]
304304,Para [Str "Backslash:",Space,Str "\\"]
305−,Para [Str "Backtick:",Space,Str "\8216"]
305+,Para [Str "Backtick:",Space,Str "`"]
306306,Para [Str "Asterisk:",Space,Str "*"]
307307,Para [Str "Underscore:",Space,Str "_"]
308308,Para [Str "Left",Space,Str "brace:",Space,Str "{"]