phase2: markdown converter with goldmark, chroma, and ASCII-translit anchors

This commit is contained in:
Sergey Filkin
2026-04-18 11:47:18 +03:00
parent cab04768b5
commit 8deba3627f
39 changed files with 5662 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package converter
import (
"fmt"
"regexp"
"strings"
"github.com/mozillazg/go-unidecode"
)
var slugRe = regexp.MustCompile(`[^a-z0-9]+`)
func translitSlug(s string, used map[string]int) string {
t := strings.ToLower(unidecode.Unidecode(s))
t = slugRe.ReplaceAllString(t, "-")
t = strings.Trim(t, "-")
if t == "" {
t = "section"
}
if n, ok := used[t]; ok && n > 0 {
used[t] = n + 1
return fmt.Sprintf("%s-%d", t, n)
}
used[t] = 1
return t
}