diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index cd277b51b..8599680cf 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -483,10 +483,15 @@ inlineToRST (Quoted DoubleQuote lst) = do else return $ "“" <> contents <> "”" inlineToRST (Cite _ lst) = inlineListToRST lst -inlineToRST (Code _ str) = +inlineToRST (Code _ str) = do + opts <- gets stOptions -- we trim the string because the delimiters must adjoin a -- non-space character; see #3496 - return $ "``" <> text (trim str) <> "``" + -- we use :literal: when the code contains backticks, since + -- :literal: allows backslash-escapes; see #3974 + return $ if '`' `elem` str + then ":literal:`" <> text (escapeString opts (trim str)) <> "`" + else "``" <> text (trim str) <> "``" inlineToRST (Str str) = do opts <- gets stOptions return $ text $ diff --git a/test/command/3974.md b/test/command/3974.md new file mode 100644 index 000000000..26ab36688 --- /dev/null +++ b/test/command/3974.md @@ -0,0 +1,6 @@ +``` +% pandoc -f native -t rst +[Code ("",[],[]) "``"] +^D +:literal:`\`\`` +```