diff options
Diffstat (limited to 'Text/Pandoc/Readers')
-rw-r--r-- | Text/Pandoc/Readers/LaTeX.hs | 61 | ||||
-rw-r--r-- | Text/Pandoc/Readers/Markdown.hs | 11 |
2 files changed, 34 insertions, 38 deletions
diff --git a/Text/Pandoc/Readers/LaTeX.hs b/Text/Pandoc/Readers/LaTeX.hs index 2ce0204ee..883c1bbd1 100644 --- a/Text/Pandoc/Readers/LaTeX.hs +++ b/Text/Pandoc/Readers/LaTeX.hs @@ -153,7 +153,6 @@ block = choice [ hrule , header , list , blockQuote - , mathBlock , comment , bibliographic , para @@ -219,26 +218,6 @@ blockQuote = (environment "quote" <|> environment "quotation") >>~ spaces >>= return . BlockQuote -- --- math block --- - -mathBlock :: GenParser Char st Block -mathBlock = mathBlockWith (begin "equation") (end "equation") <|> - mathBlockWith (begin "displaymath") (end "displaymath") <|> - mathBlockWith (try $ string "\\[") (try $ string "\\]") <?> - "math block" - -mathBlockWith :: GenParser Char st t - -> GenParser Char st end - -> GenParser Char st Block -mathBlockWith start end' = try $ do - start - spaces - result <- manyTill anyChar end' - spaces - return $ BlockQuote [Para [Math result]] - --- -- list blocks -- @@ -683,21 +662,31 @@ endline = try $ newline >> notFollowedBy blankline >> return Space -- math math :: GenParser Char st Inline -math = math1 <|> math2 <?> "math" - -math1 :: GenParser Char st Inline -math1 = try $ do - char '$' - result <- many (noneOf "$") - char '$' - return $ Math result - -math2 :: GenParser Char st Inline -math2 = try $ do - string "\\(" - result <- many (noneOf "$") - string "\\)" - return $ Math result +math = (math3 >>= return . Math DisplayMath) + <|> (math1 >>= return . Math InlineMath) + <|> (math2 >>= return . Math InlineMath) + <|> (math4 >>= return . Math DisplayMath) + <|> (math5 >>= return . Math DisplayMath) + <|> (math6 >>= return . Math DisplayMath) + <?> "math" + +math1 :: GenParser Char st String +math1 = try $ char '$' >> manyTill anyChar (char '$') + +math2 :: GenParser Char st String +math2 = try $ string "\\(" >> manyTill anyChar (try $ string "\\)") + +math3 :: GenParser Char st String +math3 = try $ char '$' >> math1 >>~ char '$' + +math4 :: GenParser Char st String +math4 = try $ (begin "equation") >> spaces >> manyTill anyChar (end "equation") + +math5 :: GenParser Char st String +math5 = try $ (begin "displaymath") >> spaces >> manyTill anyChar (end "displaymath") + +math6 :: GenParser Char st String +math6 = try $ (string "\\[") >> spaces >> manyTill anyChar (try $ string "\\]") -- -- links and images diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs index ac7096d37..f030f07ad 100644 --- a/Text/Pandoc/Readers/Markdown.hs +++ b/Text/Pandoc/Readers/Markdown.hs @@ -870,14 +870,21 @@ mathWord = many1 ((noneOf " \t\n\\$") <|> (try (char '\\') >>~ notFollowedBy (char '$'))) math :: GenParser Char ParserState Inline -math = try $ do +math = (mathDisplay >>= return . Math DisplayMath) + <|> (mathInline >>= return . Math InlineMath) + +mathDisplay :: GenParser Char ParserState String +mathDisplay = try $ char '$' >> mathInline >>~ char '$' >>~ notFollowedBy digit + +mathInline :: GenParser Char ParserState String +mathInline = try $ do failIfStrict char '$' notFollowedBy space words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline))) char '$' notFollowedBy digit - return $ Math $ joinWithSep " " words' + return $ joinWithSep " " words' emph :: GenParser Char ParserState Inline emph = ((enclosed (char '*') (notFollowedBy' strong >> char '*') inline) <|> |