@@ -137,7 +137,6 @@ block = choice [ codeBlock
137 , imageBlock
137 , imageBlock
138 , figureBlock
138 , figureBlock
139 , customCodeBlock
139 , customCodeBlock
141 , defaultRoleBlock
140 , defaultRoleBlock
142 , directive
141 , directive
@@ -392,33 +391,6 @@ extractCaption = try $ do
392 manyTill anyLine blanklines
391 manyTill anyLine blanklines
393 trimInlines . mconcat <$> many inline
392 trimInlines . mconcat <$> many inline
395−-- | The 'math' directive (from Sphinx) for display math.
396−mathBlock :: Parser [Char] st Blocks
399− mathBlockMultiline <|> mathBlockOneLine
401−mathBlockOneLine :: Parser [Char] st Blocks
402−mathBlockOneLine = try $ do
403− result <- manyTill anyChar newline
405− return $ B.para $ B.displayMath $ removeLeadingTrailingSpace result
407−mathBlockMultiline :: Parser [Char] st Blocks
408−mathBlockMultiline = try $ do
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
422lhsCodeBlock :: RSTParser Blocks
394lhsCodeBlock :: RSTParser Blocks
423lhsCodeBlock = try $ do
395lhsCodeBlock = try $ do
424 guardEnabled Ext_literate_haskell
396 guardEnabled Ext_literate_haskell
@@ -579,7 +551,7 @@ defaultRoleBlock = try $ do
579 return mempty
551 return mempty
582−-- unknown directive (e.g. comment, container, compound-paragraph)
554+-- directive (e.g. comment, container, compound-paragraph)
585directive :: RSTParser Blocks
557directive :: RSTParser Blocks
@@ -608,8 +580,16 @@ directive = try $ do
608 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
580 "highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
609 "rubric" -> B.para . B.strong <$> parseFromString
581 "rubric" -> B.para . B.strong <$> parseFromString
610 (trimInlines . mconcat <$> many inline) top
582 (trimInlines . mconcat <$> many inline) top
583+ "math" -> return $ B.para $ mconcat $ map B.displayMath
584+ $ toChunks $ top ++ "\n\n" ++ body
611 _ -> return mempty
585 _ -> return mempty
587+-- divide string by blanklines
588+toChunks :: String -> [String]
589+toChunks = dropWhile null
590+ . map (removeLeadingTrailingSpace . unlines)
591+ . splitBy (all (`elem` " \t")) . lines
614--- note block
594--- note block