aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-10-16 20:54:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-10-16 20:54:43 -0700
commit9cf9a64923c672fafd1458bda6f643ada83e2b1e (patch)
tree270136da5670107f60903c065d10438f3b11a6d4
parentcba18c19a69d05ecd3e617bcbd74780482bffd7e (diff)
downloadpandoc-9cf9a64923c672fafd1458bda6f643ada83e2b1e.tar.gz
RST writer: correctly handle inline code containing backticks.
(Use a :literal: role.) Closes #3974.
-rw-r--r--src/Text/Pandoc/Writers/RST.hs9
-rw-r--r--test/command/3974.md6
2 files changed, 13 insertions, 2 deletions
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:`\`\``
+```