aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs9
-rw-r--r--src/Text/Pandoc/Writers/RST.hs8
2 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 02154b5a3..456b23ce8 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -363,18 +363,18 @@ customCodeBlock = try $ do
-- | The 'math' directive (from Sphinx) for display math.
mathBlock :: GenParser Char st Block
-mathBlock = mathBlockMultiline <|> mathBlockOneLine
+mathBlock = try $ do
+ string ".. math::"
+ mathBlockMultiline <|> mathBlockOneLine
mathBlockOneLine :: GenParser Char st Block
mathBlockOneLine = try $ do
- string ".. math:"
result <- manyTill anyChar newline
blanklines
return $ Para [Math DisplayMath $ removeLeadingTrailingSpace result]
mathBlockMultiline :: GenParser Char st Block
mathBlockMultiline = try $ do
- string ".. math::"
blanklines
result <- indentedBlock
-- a single block can contain multiple equations, which need to go
@@ -384,7 +384,8 @@ mathBlockMultiline = try $ do
let startsWithColon (':':_) = True
startsWithColon _ = False
let lns' = dropWhile startsWithColon lns
- let eqs = map unwords $ filter (not . null) $ splitBy null lns'
+ let eqs = map (removeLeadingTrailingSpace . unlines)
+ $ filter (not . null) $ splitBy null lns'
return $ Para $ map (Math DisplayMath) eqs
lhsCodeBlock :: GenParser Char ParserState Block
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 282935bbd..db2ad0dfb 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -286,9 +286,11 @@ inlineToRST (Str str) = return $ text $ escapeString str
inlineToRST (Math t str) = do
modify $ \st -> st{ stHasMath = True }
return $ if t == InlineMath
- then ":math:`" <> text str <> "`\\ "
- else blankline $$ ".. math::" $$ blankline $$
- nest 3 (text str) $$ blankline
+ then ":math:`" <> text str <> "`" <> beforeNonBlank "\\ "
+ else if '\n' `elem` str
+ then blankline $$ ".. math::" $$
+ blankline $$ nest 3 (text str) $$ blankline
+ else blankline $$ (".. math:: " <> text str) $$ blankline
inlineToRST (RawInline _ _) = return empty
inlineToRST (LineBreak) = return cr -- there's no line break in RST
inlineToRST Space = return space