git.iko.soy/typeable/pandoc
on master help sign in
RST writer: better handling of raw latex inline.
28497d4John MacFarlane
data/templates+1−1

Submodule changed.

src/Text/Pandoc/Writers/RST.hs+12−6
@@ -48,11 +48,12 @@ import Data.Char (isSpace, toLower)
48type Refs = [([Inline], Target)]
48type Refs = [([Inline], Target)]
49
49
50data WriterState =
50data WriterState =
51− WriterState { stNotes :: [[Block]]
51+ WriterState { stNotes :: [[Block]]
52− , stLinks :: Refs
52+ , stLinks :: Refs
53− , stImages :: [([Inline], (String, String, Maybe String))]
53+ , stImages :: [([Inline], (String, String, Maybe String))]
54− , stHasMath :: Bool
54+ , stHasMath :: Bool
55+ , stHasRawTeX :: Bool
55− , stOptions :: WriterOptions
56+ , stOptions :: WriterOptions
56 }
57 }
57
58
58-- | Convert Pandoc to RST.
59-- | Convert Pandoc to RST.
@@ -60,7 +61,7 @@ writeRST :: WriterOptions -> Pandoc -> String
60writeRST opts document =
61writeRST opts document =
61 let st = WriterState { stNotes = [], stLinks = [],
62 let st = WriterState { stNotes = [], stLinks = [],
62 stImages = [], stHasMath = False,
63 stImages = [], stHasMath = False,
63− stOptions = opts }
64+ stHasRawTeX = False, stOptions = opts }
64 in evalState (pandocToRST document) st
65 in evalState (pandocToRST document) st
65
66
66-- | Return RST representation of document.
67-- | Return RST representation of document.
@@ -84,6 +85,7 @@ pandocToRST (Pandoc meta blocks) = do
84 refs <- liftM (reverse . stLinks) get >>= refsToRST
85 refs <- liftM (reverse . stLinks) get >>= refsToRST
85 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
86 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
86 hasMath <- liftM stHasMath get
87 hasMath <- liftM stHasMath get
88+ rawTeX <- liftM stHasRawTeX get
87 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
89 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
88 let context = defField "body" main
90 let context = defField "body" main
89 $ defField "toc" (writerTableOfContents opts)
91 $ defField "toc" (writerTableOfContents opts)
@@ -91,6 +93,7 @@ pandocToRST (Pandoc meta blocks) = do
91 $ defField "math" hasMath
93 $ defField "math" hasMath
92 $ defField "title" (render Nothing title :: String)
94 $ defField "title" (render Nothing title :: String)
93 $ defField "math" hasMath
95 $ defField "math" hasMath
96+ $ defField "rawtex" rawTeX
94 $ metadata
97 $ metadata
95 if writerStandalone opts
98 if writerStandalone opts
96 then return $ renderTemplate' (writerTemplate opts) context
99 then return $ renderTemplate' (writerTemplate opts) context
@@ -392,6 +395,9 @@ inlineToRST (Math t str) = do
392 else blankline $$ (".. math:: " <> text str) $$ blankline
395 else blankline $$ (".. math:: " <> text str) $$ blankline
393inlineToRST (RawInline f x)
396inlineToRST (RawInline f x)
394 | f == "rst" = return $ text x
397 | f == "rst" = return $ text x
398+ | f == "latex" || f == "tex" = do
399+ modify $ \st -> st{ stHasRawTeX = True }
400+ return $ ":raw-latex:`" <> text x <> "`"
395 | otherwise = return empty
401 | otherwise = return empty
396inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
402inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
397inlineToRST Space = return space
403inlineToRST Space = return space
tests/writer.rst+5−1
@@ -10,6 +10,10 @@ Pandoc Test Suite
10 :format: html latex
10 :format: html latex
11..
11..
12
12
13+.. role:: raw-latex(raw)
14+ :format: latex
15+..
16+
13This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
17This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
14markdown test suite.
18markdown test suite.
15
19
@@ -657,7 +661,7 @@ Ellipses…and…and….
657LaTeX
661LaTeX
658=====
662=====
659
663
660−-
664+- :raw-latex:`\cite[22-23]{smith.1899}`
661- :math:`2+2=4`
665- :math:`2+2=4`
662- :math:`x \in y`
666- :math:`x \in y`
663- :math:`\alpha \wedge \omega`
667- :math:`\alpha \wedge \omega`