aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-09-26 21:48:08 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-09-26 21:56:21 -0700
commitdf57d0930bf4c6b369b1cd35a98bd8b7238da0d1 (patch)
tree056ae4a77e907e9a5c057998fc0ab0f58e759d25 /src/Text/Pandoc/Writers
parent9b23b738cb28df357868fc0febff18e9c7c86b95 (diff)
downloadpandoc-df57d0930bf4c6b369b1cd35a98bd8b7238da0d1.tar.gz
RST writer: properly handle anchors to ids...
with spaces or leading underscore. In this cases we need the quoted form, e.g. ``` .. _`foo bar`: .. _`_foo`: ``` Side note: rST will "normalize" these identifiers anyway, ignoring the underscore: https://docutils.sourceforge.io/docs/ref/rst/directives.html#identifier-normalization Closes #7593.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 983ef412a..8b2002851 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -270,7 +270,12 @@ blockToRST (Header level (name,classes,_) inlines) = do
let headerChar = if level > 5 then ' ' else "=-~^'" !! (level - 1)
let border = literal $ T.replicate (offset contents) $ T.singleton headerChar
let anchor | T.null name || name == autoId = empty
- | otherwise = ".. _" <> literal name <> ":" $$ blankline
+ | otherwise = ".. _" <>
+ (if T.any (==':') name ||
+ T.take 1 name == "_"
+ then "`" <> literal name <> "`"
+ else literal name) <>
+ ":" $$ blankline
return $ nowrap $ anchor $$ contents $$ border $$ blankline
else do
let rub = "rubric:: " <> contents