Add autoID for definition terms

Fixes #13403
See #11566

Co-authored-by: Joe Mooring <joe@mooring.com>
This commit is contained in:
Bjørn Erik Pedersen
2025-02-15 17:13:20 +01:00
parent 9c2f8ec61b
commit 157d3703c3
9 changed files with 262 additions and 47 deletions

View File

@@ -31,7 +31,8 @@ var Empty = &Fragments{
// Builder is used to build the ToC data structure.
type Builder struct {
toc *Fragments
identifiersSet bool
toc *Fragments
}
// AddAt adds the heading to the ToC.
@@ -42,6 +43,16 @@ func (b *Builder) AddAt(h *Heading, row, level int) {
b.toc.addAt(h, row, level)
}
// SetIdentifiers sets the identifiers in the ToC.
func (b *Builder) SetIdentifiers(ids []string) {
if b.toc == nil {
b.toc = &Fragments{}
}
b.identifiersSet = true
sort.Strings(ids)
b.toc.Identifiers = ids
}
// Build returns the ToC.
func (b Builder) Build() *Fragments {
if b.toc == nil {
@@ -51,7 +62,9 @@ func (b Builder) Build() *Fragments {
b.toc.walk(func(h *Heading) {
if h.ID != "" {
b.toc.HeadingsMap[h.ID] = h
b.toc.Identifiers = append(b.toc.Identifiers, h.ID)
if !b.identifiersSet {
b.toc.Identifiers = append(b.toc.Identifiers, h.ID)
}
}
})
sort.Strings(b.toc.Identifiers)