From 68bbe9dcaecf2b191cd9792a266086dab6ca6765 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 20 Sep 2026 05:29:45 +0000 Subject: [PATCH] Org writer: avoid `=` delimiter for inline code containing `=`. Org has no escape mechanism inside verbatim text, so `=code with ==` did not parse as verbatim. Fall back to the equivalent `~...~` delimiter when the content contains `=` (and no `~`). Co-Authored-By: Claude --- src/Text/Pandoc/Writers/Org.hs | 8 +++++++- test/writer.org | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index 3b6b0673f..2676fadc8 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -548,7 +548,13 @@ inlineToOrg (Cite cs lst) = do _ -> mempty return $ "[cite" <> sty <> ":" <> citeItems <> "]" else inlineListToOrg lst -inlineToOrg (Code _ str) = return $ "=" <> literal str <> "=" +inlineToOrg (Code _ str) = return $ + -- Org offers no escape mechanism inside verbatim text; if the + -- content contains the delimiter, fall back to the other verbatim + -- delimiter. + if "=" `T.isInfixOf` str && not ("~" `T.isInfixOf` str) + then "~" <> literal str <> "~" + else "=" <> literal str <> "=" inlineToOrg (Str str) = do opts <- gets stOptions let str' = if isEnabled Ext_smart opts || isEnabled Ext_special_strings opts diff --git a/test/writer.org b/test/writer.org index 8c2974752..eb43db2b9 100644 --- a/test/writer.org +++ b/test/writer.org @@ -598,7 +598,7 @@ Ellipses...and...and.... These shouldn't be math: -- To get the famous equation, write =$e = mc^2$=. +- To get the famous equation, write ~$e = mc^2$~. - $22,000 is a /lot/ of money. So is $34,000. (It worked if “lot” is emphasized.) - Shoes ($20) and socks ($5).