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
  • ") } else if node.Level < tocLevel { @@ -924,8 +927,7 @@ func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) { } } - fmt.Fprintf(&buf, ``, headingCount) - headingCount++ + fmt.Fprintf(&buf, ``, node.HeadingID) } else { buf.WriteString("") }