Stabilize repeated layout block IDs
This commit is contained in:
parent
066bb8e92d
commit
ebbd050df4
2 changed files with 20 additions and 0 deletions
13
edge_test.go
13
edge_test.go
|
|
@ -496,6 +496,19 @@ func TestLayout_DuplicateVariantChars_Ugly(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLayout_DuplicateVariantChars_UniqueBlockIDs_Good(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
layout := NewLayout("CCC").C(Raw("content"))
|
||||
got := layout.Render(ctx)
|
||||
|
||||
for _, want := range []string{`data-block="C"`, `data-block="C.1"`, `data-block="C.2"`} {
|
||||
if !containsText(got, want) {
|
||||
t.Fatalf("CCC variant should assign unique block ID %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLayout_EmptySlots_Ugly(t *testing.T) {
|
||||
ctx := NewContext()
|
||||
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ func (l *Layout) Render(ctx *Context) string {
|
|||
|
||||
b := newTextBuilder()
|
||||
rendered := 0
|
||||
rootCounts := make(map[byte]int)
|
||||
|
||||
for i := range len(l.variant) {
|
||||
slot := l.variant[i]
|
||||
|
|
@ -194,6 +195,12 @@ func (l *Layout) Render(ctx *Context) string {
|
|||
}
|
||||
|
||||
bid := l.blockID(slot, rendered)
|
||||
if l.path == "" {
|
||||
if seen := rootCounts[slot]; seen > 0 {
|
||||
bid = string(slot) + "." + strconv.Itoa(seen)
|
||||
}
|
||||
rootCounts[slot] = rootCounts[slot] + 1
|
||||
}
|
||||
|
||||
b.WriteByte('<')
|
||||
b.WriteString(escapeHTML(meta.tag))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue