@@ -128,6 +128,7 @@ block = choice [ codeBlock
128128 , fieldList
129129 , imageBlock
130130 , customCodeBlock
131+ , mathBlock
131132 , unknownDirective
132133 , header
133134 , hrule
@@ -360,6 +361,32 @@ customCodeBlock = try $ do
360361 result <- indentedBlock
361362 return $ CodeBlock ("", ["sourceCode", language], []) $ stripTrailingNewlines result
362363
364+-- | The 'math' directive (from Sphinx) for display math.
365+mathBlock :: GenParser Char st Block
366+mathBlock = mathBlockMultiline <|> mathBlockOneLine
367+
368+mathBlockOneLine :: GenParser Char st Block
369+mathBlockOneLine = try $ do
370+ string ".. math:"
371+ result <- manyTill anyChar newline
372+ blanklines
373+ return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
374+
375+mathBlockMultiline :: GenParser Char st Block
376+mathBlockMultiline = try $ do
377+ string ".. math::"
378+ blanklines
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
389+
363390lhsCodeBlock :: GenParser Char ParserState Block
364391lhsCodeBlock = try $ do
365392 failUnlessLHS
@@ -736,6 +763,7 @@ inline = choice [ whitespace
736763 , image
737764 , superscript
738765 , subscript
766+ , math
739767 , note
740768 , smartPunctuation inline
741769 , hyphens
@@ -774,18 +802,21 @@ strong :: GenParser Char ParserState Inline
774802strong = enclosed (string "**") (try $ string "**") inline >>=
775803 return . Strong . normalizeSpaces
776804
777−interpreted :: [Char] -> GenParser Char st [Inline]
805+interpreted :: [Char] -> GenParser Char st [Char]
778806interpreted role = try $ do
779807 optional $ try $ string "\\ "
780808 result <- enclosed (string $ ":" ++ role ++ ":`") (char '`') anyChar
781809 try (string "\\ ") <|> lookAhead (count 1 $ oneOf " \t\n") <|> (eof >> return "")
782− return [Str result]
810+ return result
783811
784812superscript :: GenParser Char ParserState Inline
785−superscript = interpreted "sup" >>= (return . Superscript)
813+superscript = interpreted "sup" >>= \x -> return (Superscript [Str x])
786814
787815subscript :: GenParser Char ParserState Inline
788−subscript = interpreted "sub" >>= (return . Subscript)
816+subscript = interpreted "sub" >>= \x -> return (Subscript [Str x])
817+
818+math :: GenParser Char ParserState Inline
819+math = interpreted "math" >>= \x -> return (Math InlineMath x)
789820
790821whitespace :: GenParser Char ParserState Inline
791822whitespace = many1 spaceChar >> return Space <?> "whitespace"