git.iko.soy/typeable/pandoc
on master help sign in
RST writer: add header anchors when header has non-standard id.

Closes #3937.

commit2314534d4da815fa23f622d43a8d7a2c8902ee8e authorJohn MacFarlane <jgm@berkeley.edu> dateWed 27 Sep 2017, 20:42 (9 years ago) parent394b198
2 files changed+19−1
src/Text/Pandoc/Writers/RST.hs+6−1 test/command/3937.md+13
src/Text/Pandoc/Writers/RST.hs+6−1
@@ -239,12 +239,17 @@ blockToRST HorizontalRule =
239239 return $ blankline $$ "--------------" $$ blankline
240240blockToRST (Header level (name,classes,_) inlines) = do
241241 contents <- inlineListToRST inlines
242+ -- we calculate the id that would be used by auto_identifiers
243+ -- so we know whether to print an explicit identifier
244+ let autoId = uniqueIdent inlines mempty
242245 isTopLevel <- gets stTopLevel
243246 if isTopLevel
244247 then do
245248 let headerChar = if level > 5 then ' ' else "=-~^'" !! (level - 1)
246249 let border = text $ replicate (offset contents) headerChar
247− return $ nowrap $ contents $$ border $$ blankline
250+ let anchor | null name || name == autoId = empty
251+ | otherwise = ".. " <> text name <> ":" $$ blankline
252+ return $ nowrap $ anchor $$ contents $$ border $$ blankline
248253 else do
249254 let rub = "rubric:: " <> contents
250255 let name' | null name = empty
test/command/3937.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -t rst
3+# My Great Section {#mysection}
4+# Other section
5+^D
6+.. mysection:
7+
8+My Great Section
9+================
10+
11+Other section
12+=============
13+```