func buildTOCTree()

in cqlprotodoc/main.go [40:59]


func buildTOCTree(entries []spec.TOCEntry, sectionNumbers map[string]struct{}) []*TOCNode {
	var root TOCNode
	stack := []*TOCNode{&root}
	for _, e := range entries {
		level := strings.Count(e.Number, ".") + 1
		if len(stack) > level {
			stack = stack[:level]
		}
		parent := stack[len(stack)-1]
		_, exists := sectionNumbers[e.Number]
		node := &TOCNode{
			TOCEntry: e,
			Children: nil,
			Exists:   exists,
		}
		parent.Children = append(parent.Children, node)
		stack = append(stack, node)
	}
	return root.Children
}