Skip to content

Commit 3c5717e

Browse files
Fix: Initialize IDGenerator map and improve Markdown
1 parent df3b620 commit 3c5717e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/markdown/convert.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,27 @@ type IDGenerator struct {
4242
used map[string]bool
4343
}
4444

45+
// ensureInit initializes the internal map if not already.
46+
func (g *IDGenerator) ensureInit() {
47+
if g.used == nil {
48+
g.used = make(map[string]bool)
49+
}
50+
}
51+
4552
// Generate an ID
4653
func (g *IDGenerator) Generate(value []byte, _ ast.NodeKind) []byte {
54+
g.ensureInit()
4755
return []byte(slug.Generate(string(value)))
4856
}
4957

5058
// Put an ID to the list of already used IDs
5159
func (g *IDGenerator) Put(value []byte) {
60+
g.ensureInit()
5261
g.used[util.BytesToReadOnlyString(value)] = true
5362
}
63+
64+
// Has checks if the given ID is already used.
65+
func (g *IDGenerator) Has(value []byte) bool {
66+
(g *IDGenerator)
67+
return g.used[util.BytesToReadOnlyString(value)]
68+
}

0 commit comments

Comments
 (0)