aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-09-27 20:42:04 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-09-27 20:42:04 -0700
commit2314534d4da815fa23f622d43a8d7a2c8902ee8e (patch)
tree7900d6b8d515a20c7edf8ed669cb33ae6f31add6 /src
parent394b1985b13780310fd2b3bec7ca9f635a3221cb (diff)
downloadpandoc-2314534d4da815fa23f622d43a8d7a2c8902ee8e.tar.gz
RST writer: add header anchors when header has non-standard id.
Closes #3937.
Diffstat (limited to 'src')
-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 8c941f568..94c135715 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -239,12 +239,17 @@ blockToRST HorizontalRule =
return $ blankline $$ "--------------" $$ blankline
blockToRST (Header level (name,classes,_) inlines) = do
contents <- inlineListToRST inlines
+ -- we calculate the id that would be used by auto_identifiers
+ -- so we know whether to print an explicit identifier
+ let autoId = uniqueIdent inlines mempty
isTopLevel <- gets stTopLevel
if isTopLevel
then do
let headerChar = if level > 5 then ' ' else "=-~^'" !! (level - 1)
let border = text $ replicate (offset contents) headerChar
- return $ nowrap $ contents $$ border $$ blankline
+ let anchor | null name || name == autoId = empty
+ | otherwise = ".. " <> text name <> ":" $$ blankline
+ return $ nowrap $ anchor $$ contents $$ border $$ blankline
else do
let rub = "rubric:: " <> contents
let name' | null name = empty