aboutsummaryrefslogtreecommitdiff
path: root/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-01-04 18:59:00 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-01-04 18:59:00 +0000
commit0921704d922efd394c7a6a961ea113d7f629231b (patch)
tree4832d72d70d9c71faa76f2bb4316b7698bb5346a /Text/Pandoc/Writers
parentec3f6b649f1059320816fc5dd40a4ec44941d159 (diff)
downloadpandoc-0921704d922efd394c7a6a961ea113d7f629231b.tar.gz
Use an interpreted text role to render math in restructuredText.
See http://www.american.edu/econ/itex2mml/mathhack.rst for the strategy. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1168 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text/Pandoc/Writers')
-rw-r--r--Text/Pandoc/Writers/RST.hs27
1 files changed, 20 insertions, 7 deletions
diff --git a/Text/Pandoc/Writers/RST.hs b/Text/Pandoc/Writers/RST.hs
index 08ff9b928..e7708d9a8 100644
--- a/Text/Pandoc/Writers/RST.hs
+++ b/Text/Pandoc/Writers/RST.hs
@@ -44,7 +44,7 @@ data WriterState =
WriterState { stNotes :: [[Block]]
, stLinks :: KeyTable
, stImages :: KeyTable
- , stIncludes :: [Doc]
+ , stIncludes :: [String]
, stOptions :: WriterOptions
}
@@ -69,12 +69,14 @@ pandocToRST (Pandoc meta blocks) = do
then metaBlock $+$ text (writerHeader opts)
else empty
body <- blockListToRST blocks
+ includes <- get >>= (return . concat . stIncludes)
+ let includes' = if null includes then empty else text includes
notes <- get >>= (notesToRST . reverse . stNotes)
-- note that the notes may contain refs, so we do them first
refs <- get >>= (keyTableToRST . reverse . stLinks)
pics <- get >>= (pictTableToRST . reverse . stImages)
- return $ head $+$ before' $+$ body $+$ notes $+$ text "" $+$ refs $+$
- pics $+$ after'
+ return $ head $+$ before' $+$ includes' $+$ body $+$ notes $+$ text "" $+$
+ refs $+$ pics $+$ after'
-- | Return RST representation of reference key table.
keyTableToRST :: KeyTable -> State WriterState Doc
@@ -117,8 +119,11 @@ pictToRST (label, (src, _)) = do
-- | Take list of inline elements and return wrapped doc.
wrappedRST :: WriterOptions -> [Inline] -> State WriterState Doc
-wrappedRST opts inlines = mapM (wrapIfNeeded opts inlineListToRST)
- (splitBy LineBreak inlines) >>= return . vcat
+wrappedRST opts inlines = do
+ lineBreakDoc <- inlineToRST LineBreak
+ chunks <- mapM (wrapIfNeeded opts inlineListToRST)
+ (splitBy LineBreak inlines)
+ return $ vcat $ intersperse lineBreakDoc chunks
-- | Escape special characters for RST.
escapeString :: String -> String
@@ -293,10 +298,18 @@ inlineToRST Apostrophe = return $ char '\''
inlineToRST Ellipses = return $ text "..."
inlineToRST (Code str) = return $ text $ "``" ++ str ++ "``"
inlineToRST (Str str) = return $ text $ escapeString str
-inlineToRST (Math str) = return $ text $ "$" ++ str ++ "$"
+inlineToRST (Math str) = do
+ includes <- get >>= (return . stIncludes)
+ let rawMathRole = ".. role:: math(raw)\n\
+ \ :format: html latex\n"
+ if not (rawMathRole `elem` includes)
+ then modify $ \st -> st { stIncludes = rawMathRole : includes }
+ else return ()
+ return $ text $ ":math:`$" ++ str ++ "$`"
inlineToRST (TeX str) = return empty
inlineToRST (HtmlInline str) = return empty
-inlineToRST (LineBreak) = return $ char ' ' -- RST doesn't have linebreaks
+inlineToRST (LineBreak) = do
+ return $ empty -- there's no line break in RST
inlineToRST Space = return $ char ' '
inlineToRST (Link [Code str] (src, tit)) | src == str ||
src == "mailto:" ++ str = do