@@ -137,7 +137,6 @@ block = choice [ codeBlock
137137 , imageBlock
138138 , figureBlock
139139 , customCodeBlock
140− , mathBlock
141140 , defaultRoleBlock
142141 , directive
143142 , header
@@ -392,33 +391,6 @@ extractCaption = try $ do
392391 manyTill anyLine blanklines
393392 trimInlines . mconcat <$> many inline
394393
395−-- | The 'math' directive (from Sphinx) for display math.
396−mathBlock :: Parser [Char] st Blocks
397−mathBlock = try $ do
398− string ".. math::"
399− mathBlockMultiline <|> mathBlockOneLine
400−
401−mathBlockOneLine :: Parser [Char] st Blocks
402−mathBlockOneLine = try $ do
403− result <- manyTill anyChar newline
404− blanklines
405− return $ B.para $ B.displayMath $ removeLeadingTrailingSpace result
406−
407−mathBlockMultiline :: Parser [Char] st Blocks
408−mathBlockMultiline = try $ do
409− blanklines
410− result <- indentedBlock
411− -- a single block can contain multiple equations, which need to go
412− -- in separate Pandoc math elements
413− let lns = map removeLeadingTrailingSpace $ lines result
414− -- drop :label, :nowrap, etc.
415− let startsWithColon (':':_) = True
416− startsWithColon _ = False
417− let lns' = dropWhile startsWithColon lns
418− let eqs = map (removeLeadingTrailingSpace . unlines)
419− $ filter (not . null) $ splitBy null lns'
420− return $ B.para $ mconcat $ map B.displayMath eqs
421−
422394lhsCodeBlock :: RSTParser Blocks
423395lhsCodeBlock = try $ do
424396 guardEnabled Ext_literate_haskell
@@ -579,7 +551,7 @@ defaultRoleBlock = try $ do
579551 return mempty
580552
581553--
582−-- unknown directive (e.g. comment, container, compound-paragraph)
554+-- directive (e.g. comment, container, compound-paragraph)
583555--
584556
585557directive :: RSTParser Blocks
@@ -608,8 +580,16 @@ directive = try $ do
608580 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
609581 "rubric" -> B.para . B.strong <$> parseFromString
610582 (trimInlines . mconcat <$> many inline) top
583+ "math" -> return $ B.para $ mconcat $ map B.displayMath
584+ $ toChunks $ top ++ "\n\n" ++ body
611585 _ -> return mempty
612586
587+-- divide string by blanklines
588+toChunks :: String -> [String]
589+toChunks = dropWhile null
590+ . map (removeLeadingTrailingSpace . unlines)
591+ . splitBy (all (`elem` " \t")) . lines
592+
613593---
614594--- note block
615595---