diff --git a/html.go b/html.go index 63b7435..7db102f 100644 --- a/html.go +++ b/html.go @@ -908,7 +908,10 @@ func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) { if node.Type == Heading && !node.HeadingData.IsTitleblock { inHeading = entering if entering { - node.HeadingID = fmt.Sprintf("toc_%d", headingCount) + if node.HeadingID == "" { + node.HeadingID = fmt.Sprintf("toc_%d", headingCount) + headingCount++ + } if node.Level == tocLevel { buf.WriteString("\n\n