Fix bug: AutoHeadingIDs being ignored

This commit is contained in:
Almog Baku 2020-03-13 16:03:05 +02:00 committed by GitHub
parent 3b2b20c8cb
commit 75b4f49c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -908,7 +908,10 @@ func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) {
if node.Type == Heading && !node.HeadingData.IsTitleblock {
inHeading = entering
if entering {
if node.HeadingID == "" {
node.HeadingID = fmt.Sprintf("toc_%d", headingCount)
headingCount++
}
if node.Level == tocLevel {
buf.WriteString("</li>\n\n<li>")
} else if node.Level < tocLevel {
@ -924,8 +927,7 @@ func (r *HTMLRenderer) writeTOC(w io.Writer, ast *Node) {
}
}
fmt.Fprintf(&buf, `<a href="#toc_%d">`, headingCount)
headingCount++
fmt.Fprintf(&buf, `<a href="#%s">`, node.HeadingID)
} else {
buf.WriteString("</a>")
}