@@ -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