aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-08-10 23:45:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-08-10 23:45:16 -0700
commit9591fc96147610fddd210ae6396f54850018754e (patch)
tree82fa7dc5075003a221bdb2e00545f70e0ce96843 /src/Text/Pandoc/Readers
parenteb4d522a56de3455f9b31841a04adf64c8dafa90 (diff)
downloadpandoc-9591fc96147610fddd210ae6396f54850018754e.tar.gz
Implemented Ext_tex_math_single_backslash, Ext_tex_math_double_backslash.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 1cabf70b5..8a1299de6 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1169,34 +1169,42 @@ code = try $ do
optional whitespace >> attributes)
return $ return $ B.codeWith attr $ removeLeadingTrailingSpace $ concat result
-mathWord :: Parser [Char] st String
-mathWord = liftM concat $ many1 mathChunk
-
-mathChunk :: Parser [Char] st String
-mathChunk = do char '\\'
- c <- anyChar
- return ['\\',c]
- <|> many1 (satisfy $ \c -> not (isBlank c || c == '\\' || c == '$'))
-
math :: Parser [Char] ParserState (F Inlines)
math = (return . B.displayMath <$> (mathDisplay >>= applyMacros'))
<|> (return . B.math <$> (mathInline >>= applyMacros'))
mathDisplay :: Parser [Char] ParserState String
-mathDisplay = try $ do
- guardEnabled Ext_tex_math_dollars
- string "$$"
- many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
+mathDisplay =
+ (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
+ <|> (guardEnabled Ext_tex_math_single_backslash >>
+ mathDisplayWith "\\[" "\\]")
+ <|> (guardEnabled Ext_tex_math_double_backslash >>
+ mathDisplayWith "\\\\[" "\\\\]")
+
+mathDisplayWith :: String -> String -> Parser [Char] ParserState String
+mathDisplayWith op cl = try $ do
+ string op
+ many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
mathInline :: Parser [Char] ParserState String
-mathInline = try $ do
- guardEnabled Ext_tex_math_dollars
- char '$'
+mathInline =
+ (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
+ <|> (guardEnabled Ext_tex_math_single_backslash >>
+ mathInlineWith "\\(" "\\)")
+ <|> (guardEnabled Ext_tex_math_double_backslash >>
+ mathInlineWith "\\\\(" "\\\\)")
+
+mathInlineWith :: String -> String -> Parser [Char] ParserState String
+mathInlineWith op cl = try $ do
+ string op
notFollowedBy space
- words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline)))
- char '$'
- notFollowedBy digit
- return $ intercalate " " words'
+ words' <- many1Till (count 1 (noneOf "\n\\")
+ <|> (char '\\' >> anyChar >>= \c -> return ['\\',c])
+ <|> count 1 newline <* notFollowedBy' blankline
+ *> return " ")
+ (try $ string cl)
+ notFollowedBy digit -- to prevent capture of $5
+ return $ concat words'
-- to avoid performance problems, treat 4 or more _ or * or ~ or ^ in a row
-- as a literal rather than attempting to parse for emph/strong/strikeout/super/sub