go-html/path.go
Virgil 2e8886bbd7
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
feat(html): relax block id parsing
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-04 00:57:06 +00:00

38 lines
730 B
Go

package html
import "strings"
// path.go: ParseBlockID extracts the slot sequence from a data-block ID.
// Example: ParseBlockID("L-0-C-0") returns []byte{'L', 'C'}.
func ParseBlockID(id string) []byte {
if id == "" {
return nil
}
// Split on "-" and require the exact structural pattern:
// slot, numeric index, slot, numeric index, ...
var slots []byte
i := 0
for part := range strings.SplitSeq(id, "-") {
if i%2 == 0 {
if len(part) != 1 {
return nil
}
slots = append(slots, part[0])
} else {
if part == "" {
return nil
}
for j := range len(part) {
if part[j] < '0' || part[j] > '9' {
return nil
}
}
}
i++
}
if i == 0 || i%2 != 0 {
return nil
}
return slots
}