git.iko.soy/typeable/pandoc
on master help sign in
Make sure \write18 is parsed as raw LaTeX.

The change is in the LaTeX reader's treatment of raw commands, but it also affects the Markdown reader.

commit013fd1c6b68f2c061202d931f541aa4877ae543f authorJohn MacFarlane <jgm@berkeley.edu> dateWed 12 Jul 2017, 13:58 (9 years ago) parent41209ea
5 files changed+28−9
src/Text/Pandoc/Readers/LaTeX.hs+9−7 test/command/3494.md+2−1 test/command/3577.md+2 test/command/write18.md+14 test/latex-reader.native+1−1
src/Text/Pandoc/Readers/LaTeX.hs+9−7
@@ -1049,14 +1049,12 @@ inlineCommand' :: PandocMonad m => LP m Inlines
10491049inlineCommand' = try $ do
10501050 Tok _ (CtrlSeq name) cmd <- anyControlSeq
10511051 guard $ name /= "begin" && name /= "end"
1052− (star, rawstar) <- withRaw $ option "" ("*" <$ symbol '*' <* optional sp)
1052+ star <- option "" ("*" <$ symbol '*' <* optional sp)
10531053 let name' = name <> star
10541054 let names = ordNub [name', name] -- check non-starred as fallback
10551055 let raw = do
10561056 guard $ isInlineCommand name || not (isBlockCommand name)
1057− (_, rawargs) <- withRaw
1058− (skipangles *> skipopts *> option "" dimenarg *> many braced)
1059− let rawcommand = T.unpack $ cmd <> untokenize (rawstar ++ rawargs)
1057+ rawcommand <- getRawCommand (cmd <> star)
10601058 (guardEnabled Ext_raw_tex >> return (rawInline "latex" rawcommand))
10611059 <|> ignore rawcommand
10621060 lookupListDefault raw names inlineCommands
@@ -1353,7 +1351,11 @@ rawInlineOr name' fallback = do
13531351getRawCommand :: PandocMonad m => Text -> LP m String
13541352getRawCommand txt = do
13551353 (_, rawargs) <- withRaw
1356− (many (try (optional sp *> opt)) *>
1354+ ((if txt == "\\write"
1355+ then () <$ satisfyTok isWordTok -- digits
1356+ else return ()) *>
1357+ skipangles *>
1358+ skipopts *>
13571359 option "" (try (optional sp *> dimenarg)) *>
13581360 many braced)
13591361 return $ T.unpack (txt <> untokenize rawargs)
@@ -1631,7 +1633,7 @@ blockCommand = try $ do
16311633 let names = ordNub [name', name]
16321634 let raw = do
16331635 guard $ isBlockCommand name || not (isInlineCommand name)
1634− rawBlock "latex" <$> getRawCommand txt
1636+ rawBlock "latex" <$> getRawCommand (txt <> star)
16351637 lookupListDefault raw names blockCommands
16361638
16371639closing :: PandocMonad m => LP m Blocks
@@ -2128,8 +2130,8 @@ block = (mempty <$ spaces1)
21282130 <|> environment
21292131 <|> include
21302132 <|> macroDef
2131− <|> paragraph
21322133 <|> blockCommand
2134+ <|> paragraph
21332135 <|> grouped block
21342136
21352137blocks :: PandocMonad m => LP m Blocks
test/command/3494.md+2−1
@@ -25,7 +25,8 @@
2525<td style="text-align: left;">thank you</td>
2626</tr>
2727<tr class="odd">
28−<td style="text-align: right;"><em>blah</em></td>
28+<td style="text-align: right;">
29+<p><em>blah</em></p></td>
2930<td style="text-align: left;"><em>blah</em></td>
3031<td style="text-align: left;"><em>blah</em></td>
3132</tr>
test/command/3577.md+2
@@ -15,9 +15,11 @@
1515 \caption{Subfigure with Subfloat}
1616\end{figure}
1717^D
18+
1819<figure>
1920<img src="img1.jpg" alt="Caption 1" /><figcaption>Caption 1</figcaption>
2021</figure>
22+
2123<figure>
2224<img src="img2.jpg" alt="Caption 2" /><figcaption>Caption 2</figcaption>
2325</figure>
test/command/write18.mdnew file+14
@@ -0,0 +1,14 @@
1+Handle \write18{..} as raw tex:
2+```
3+% pandoc -t native
4+\write18{git --version}
5+^D
6+[RawBlock (Format "latex") "\\write18{git --version}"]
7+```
8+
9+```
10+% pandoc -f latex+raw_tex -t native
11+\write18{git --version}
12+^D
13+[RawBlock (Format "latex") "\\write18{git --version}"]
14+```
test/latex-reader.native+1−1
@@ -261,7 +261,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
261261,Header 1 ("latex",[],[]) [Str "LaTeX"]
262262,BulletList
263263 [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str "22-23"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [RawInline (Format "latex") "\\cite[22-23]{smith.1899}"]]]
264− ,[Para [RawInline (Format "latex") "\\doublespacing"]]
264+ ,[RawBlock (Format "latex") "\\doublespacing"]
265265 ,[Para [Math InlineMath "2+2=4"]]
266266 ,[Para [Math InlineMath "x \\in y"]]
267267 ,[Para [Math InlineMath "\\alpha \\wedge \\omega"]]