git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Don't parse latex/context environments as inline.
commitd3667f9aac2e8436f9446f4200fd9c7c13da50dd authorJohn MacFarlane <jgm@berkeley.edu> dateMon 24 Jan 2011, 22:12 (16 years ago) parenteb26fa6
1 file changed+15−9
src/Text/Pandoc/Readers/Markdown.hs+15−9
src/Text/Pandoc/Readers/Markdown.hs+15−9
@@ -932,12 +932,12 @@ failIfLink (Link _ _) = pzero
932932failIfLink elt = return elt
933933
934934escapedChar :: GenParser Char ParserState Inline
935−escapedChar = do
935+escapedChar = try $ do
936936 char '\\'
937937 state <- getState
938− result <- option '\\' $ if stateStrict state
939− then oneOf "\\`*_{}[]()>#+-.!~"
940− else satisfy (not . isAlphaNum)
938+ result <- if stateStrict state
939+ then oneOf "\\`*_{}[]()>#+-.!~"
940+ else satisfy (not . isAlphaNum)
941941 return $ case result of
942942 ' ' -> Str "\160" -- "\ " is a nonbreaking space
943943 '\n' -> LineBreak -- "\[newline]" is a linebreak
@@ -961,7 +961,11 @@ exampleRef = try $ do
961961
962962symbol :: GenParser Char ParserState Inline
963963symbol = do
964− result <- noneOf "<\n\t "
964+ result <- noneOf "<\\\n\t "
965+ <|> try (do lookAhead $ char '\\'
966+ notFollowedBy' $ rawLaTeXEnvironment'
967+ <|> rawConTeXtEnvironment'
968+ char '\\')
965969 return $ Str [result]
966970
967971-- parses inline code, between n `s and n `s
@@ -1185,11 +1189,13 @@ inlineNote = try $ do
11851189 return $ Note [Para contents]
11861190
11871191rawLaTeXInline' :: GenParser Char ParserState Inline
1188−rawLaTeXInline' = do
1192+rawLaTeXInline' = try $ do
11891193 failIfStrict
1190− (rawConTeXtEnvironment' >>= return . RawInline "context")
1191− <|> (rawLaTeXEnvironment' >>= return . RawInline "latex")
1192− <|> rawLaTeXInline
1194+ lookAhead $ char '\\'
1195+ notFollowedBy' $ rawLaTeXEnvironment'
1196+ <|> rawConTeXtEnvironment'
1197+ RawInline _ s <- rawLaTeXInline
1198+ return $ RawInline "tex" s -- "tex" because it might be context or latex
11931199
11941200rawConTeXtEnvironment' :: GenParser Char st String
11951201rawConTeXtEnvironment' = try $ do