@@ -128,6 +128,7 @@ block = choice [ codeBlock
128 , fieldList
128 , fieldList
129 , imageBlock
129 , imageBlock
130 , customCodeBlock
130 , customCodeBlock
131 , unknownDirective
132 , unknownDirective
@@ -360,6 +361,32 @@ customCodeBlock = try $ do
360 result <- indentedBlock
361 result <- indentedBlock
361 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
362 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
364+-- | The 'math' directive (from Sphinx) for display math.
365+mathBlock :: GenParser Char st Block
366+mathBlock = mathBlockMultiline <|> mathBlockOneLine
368+mathBlockOneLine :: GenParser Char st Block
369+mathBlockOneLine = try $ do
371+ result <- manyTill anyChar newline
373+ return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
375+mathBlockMultiline :: GenParser Char st Block
376+mathBlockMultiline = try $ do
379+ result <- indentedBlock
380+ -- a single block can contain multiple equations, which need to go
381+ -- in separate Pandoc math elements
382+ let lns = map removeLeadingTrailingSpace $ lines result
383+ -- drop :label, :nowrap, etc.
384+ let startsWithColon (':':_) = True
385+ startsWithColon _ = False
386+ let lns' = dropWhile startsWithColon lns
387+ let eqs = map unwords $ filter (not . null) $ splitBy null lns'
388+ return $ Para $ map (Math DisplayMath) eqs
363lhsCodeBlock :: GenParser Char ParserState Block
390lhsCodeBlock :: GenParser Char ParserState Block
364lhsCodeBlock = try $ do
391lhsCodeBlock = try $ do
365 failUnlessLHS
392 failUnlessLHS
@@ -736,6 +763,7 @@ inline = choice [ whitespace
737 , superscript
764 , superscript
738 , subscript
765 , subscript
740 , smartPunctuation inline
768 , smartPunctuation inline
741 , hyphens
769 , hyphens
@@ -774,18 +802,21 @@ strong :: GenParser Char ParserState Inline
774strong = enclosed (string "**") (try $ string "**") inline >>=
802strong = enclosed (string "**") (try $ string "**") inline >>=
775 return . Strong . normalizeSpaces
803 return . Strong . normalizeSpaces
777−interpreted :: [Char] -> GenParser Char st [Inline]
805+interpreted :: [Char] -> GenParser Char st [Char]
778interpreted role = try $ do
806interpreted role = try $ do
779 optional $ try $ string "\\ "
807 optional $ try $ string "\\ "
780 result <- enclosed (string $ ":" ++ role ++ ":`") (char '`') anyChar
808 result <- enclosed (string $ ":" ++ role ++ ":`") (char '`') anyChar
781 try (string "\\ ") <|> lookAhead (count 1 $ oneOf " \t\n") <|> (eof >> return "")
809 try (string "\\ ") <|> lookAhead (count 1 $ oneOf " \t\n") <|> (eof >> return "")
782− return [Str result]
810+ return result
784superscript :: GenParser Char ParserState Inline
812superscript :: GenParser Char ParserState Inline
785−superscript = interpreted "sup" >>= (return . Superscript)
813+superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])
787subscript :: GenParser Char ParserState Inline
815subscript :: GenParser Char ParserState Inline
788−subscript = interpreted "sub" >>= (return . Subscript)
816+subscript = interpreted "sub" >>= \x -> return (Subscript [Str x])
818+math :: GenParser Char ParserState Inline
819+math = interpreted "math" >>= \x -> return (Math InlineMath x)
790whitespace :: GenParser Char ParserState Inline
821whitespace :: GenParser Char ParserState Inline
791whitespace = many1 spaceChar >> return Space <?> "whitespace"
822whitespace = many1 spaceChar >> return Space <?> "whitespace"