summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-29 16:59:41 -0400
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-29 16:59:41 -0400
commit487d01118fb55c351f61a58d2b5411ae6de30629 (patch)
tree0574219ebeb1a1de0bb7755071a9d76262d7481c /src/Text/Pandoc
parent3a589b7bca6282e6dd914ce9ab73ed2d52f747ab (diff)
RST reader: Consolidated math block parsers into directive.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index fe44443c2..0b01d3b53 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -137,7 +137,6 @@ block = choice [ codeBlock
, imageBlock
, figureBlock
, customCodeBlock
- , mathBlock
, defaultRoleBlock
, directive
, header
@@ -392,33 +391,6 @@ extractCaption = try $ do
manyTill anyLine blanklines
trimInlines . mconcat <$> many inline
--- | The 'math' directive (from Sphinx) for display math.
-mathBlock :: Parser [Char] st Blocks
-mathBlock = try $ do
- string ".. math::"
- mathBlockMultiline <|> mathBlockOneLine
-
-mathBlockOneLine :: Parser [Char] st Blocks
-mathBlockOneLine = try $ do
- result <- manyTill anyChar newline
- blanklines
- return $ B.para $ B.displayMath $ removeLeadingTrailingSpace result
-
-mathBlockMultiline :: Parser [Char] st Blocks
-mathBlockMultiline = try $ do
- blanklines
- result <- indentedBlock
- -- a single block can contain multiple equations, which need to go
- -- in separate Pandoc math elements
- let lns = map removeLeadingTrailingSpace $ lines result
- -- drop :label, :nowrap, etc.
- let startsWithColon (':':_) = True
- startsWithColon _ = False
- let lns' = dropWhile startsWithColon lns
- let eqs = map (removeLeadingTrailingSpace . unlines)
- $ filter (not . null) $ splitBy null lns'
- return $ B.para $ mconcat $ map B.displayMath eqs
-
lhsCodeBlock :: RSTParser Blocks
lhsCodeBlock = try $ do
guardEnabled Ext_literate_haskell
@@ -579,7 +551,7 @@ defaultRoleBlock = try $ do
return mempty
--
--- unknown directive (e.g. comment, container, compound-paragraph)
+-- directive (e.g. comment, container, compound-paragraph)
--
directive :: RSTParser Blocks
@@ -608,8 +580,16 @@ directive = try $ do
"highlights" -> B.blockQuote <$> parseFromString parseBlocks body'
"rubric" -> B.para . B.strong <$> parseFromString
(trimInlines . mconcat <$> many inline) top
+ "math" -> return $ B.para $ mconcat $ map B.displayMath
+ $ toChunks $ top ++ "\n\n" ++ body
_ -> return mempty
+-- divide string by blanklines
+toChunks :: String -> [String]
+toChunks = dropWhile null
+ . map (removeLeadingTrailingSpace . unlines)
+ . splitBy (all (`elem` " \t")) . lines
+
---
--- note block
---