aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-04-07 22:05:17 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-04-07 22:07:38 -0700
commit28497d484e85fd495e92f06416f978763f333518 (patch)
tree9b25c035bb7277158b3cb22b6d93d37685e3f564 /src
parentca6a8d62f28a54f739a9fc8a09d813157ee808ea (diff)
downloadpandoc-28497d484e85fd495e92f06416f978763f333518.tar.gz
RST writer: better handling of raw latex inline.
We use `` :raw-latex:`...` `` and add a definition for this role to the template. Closes #1961.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 717a47000..7d1e22baa 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -48,11 +48,12 @@ import Data.Char (isSpace, toLower)
type Refs = [([Inline], Target)]
data WriterState =
- WriterState { stNotes :: [[Block]]
- , stLinks :: Refs
- , stImages :: [([Inline], (String, String, Maybe String))]
- , stHasMath :: Bool
- , stOptions :: WriterOptions
+ WriterState { stNotes :: [[Block]]
+ , stLinks :: Refs
+ , stImages :: [([Inline], (String, String, Maybe String))]
+ , stHasMath :: Bool
+ , stHasRawTeX :: Bool
+ , stOptions :: WriterOptions
}
-- | Convert Pandoc to RST.
@@ -60,7 +61,7 @@ writeRST :: WriterOptions -> Pandoc -> String
writeRST opts document =
let st = WriterState { stNotes = [], stLinks = [],
stImages = [], stHasMath = False,
- stOptions = opts }
+ stHasRawTeX = False, stOptions = opts }
in evalState (pandocToRST document) st
-- | Return RST representation of document.
@@ -84,6 +85,7 @@ pandocToRST (Pandoc meta blocks) = do
refs <- liftM (reverse . stLinks) get >>= refsToRST
pics <- liftM (reverse . stImages) get >>= pictRefsToRST
hasMath <- liftM stHasMath get
+ rawTeX <- liftM stHasRawTeX get
let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
let context = defField "body" main
$ defField "toc" (writerTableOfContents opts)
@@ -91,6 +93,7 @@ pandocToRST (Pandoc meta blocks) = do
$ defField "math" hasMath
$ defField "title" (render Nothing title :: String)
$ defField "math" hasMath
+ $ defField "rawtex" rawTeX
$ metadata
if writerStandalone opts
then return $ renderTemplate' (writerTemplate opts) context
@@ -392,6 +395,9 @@ inlineToRST (Math t str) = do
else blankline $$ (".. math:: " <> text str) $$ blankline
inlineToRST (RawInline f x)
| f == "rst" = return $ text x
+ | f == "latex" || f == "tex" = do
+ modify $ \st -> st{ stHasRawTeX = True }
+ return $ ":raw-latex:`" <> text x <> "`"
| otherwise = return empty
inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
inlineToRST Space = return space