Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Keep the Releases channels cell a table cell

bbbfad25f18c22f6b3362a243c00beaff110d0e0 · Keenan Nemetz · 2d ago · parent 0a12642f

Keep the Releases channels cell a table cell

The Releases table put .label-row on the td itself. That class is
display: inline-flex, so the cell stopped being a table cell: the browser
wrapped it in an anonymous cell, the real column drew no border where it
sat, and the element's own border-bottom was painted over its text instead.
The row separators therefore broke around the Channels column, and a row
with no channel showed a stray short line in the gap.

Wrap the labels in a div inside the cell, as issues.html already does.

Add a test that reads display from the stylesheet and fails when a template
puts a class with a non-table display directly on a td or th, so the next
label cell does not reintroduce the anonymous-cell border.

Fixes 01M8QNH16E5SJ04T6NZJMJQK09.

server/web/templates_test.go +67

@@ -44,3 +44,70 @@ func TestTemplatesCarryNoHTMXEval(t *testing.T) {
44 44 }
45 45 }
46 46 }
47
48 // A td or th that carries a class setting a non-table display stops being a
49 // table cell. The browser wraps it in an anonymous cell, so the real cell draws
50 // no border and the element's own border-bottom spans its text instead, which
51 // breaks the row separator around it (the Releases channels column did this
52 // with .label-row). A wrapper inside the cell keeps both: a td holding labels
53 // is written <td><div class="label-row">…</div></td>.
54
55 var (
56 cssRule = regexp.MustCompile(`(?s)([^{}]+)\{([^{}]*)\}`)
57 cssDisplay = regexp.MustCompile(`(?:^|[;\s])display:\s*([^;}]+)`)
58 cssClass = regexp.MustCompile(`\.[-\w]+`)
59 cellClass = regexp.MustCompile(`<(?:td|th)\s+class="([^"]*)"`)
60 selectorPart = regexp.MustCompile(`[\s>+~]+`)
61 )
62
63 // nonTableCellClasses maps each class the stylesheet gives a display other than
64 // table-cell to that display. Only the subject of a selector counts, so
65 // `.label-row .label` does not implicate .label.
66 func nonTableCellClasses(t *testing.T) map[string]string {
67 t.Helper()
68 css, err := fs.ReadFile(staticFS, "static/vole.css")
69 if err != nil {
70 t.Fatal(err)
71 }
72 classes := map[string]string{}
73 for _, rule := range cssRule.FindAllStringSubmatch(string(css), -1) {
74 m := cssDisplay.FindStringSubmatch(rule[2])
75 if m == nil {
76 continue
77 }
78 display := strings.TrimSpace(m[1])
79 if strings.HasPrefix(display, "table") {
80 continue
81 }
82 for _, selector := range strings.Split(rule[1], ",") {
83 parts := selectorPart.Split(strings.TrimSpace(selector), -1)
84 subject := parts[len(parts)-1]
85 for _, class := range cssClass.FindAllString(subject, -1) {
86 classes[strings.TrimPrefix(class, ".")] = display
87 }
88 }
89 }
90 return classes
91 }
92
93 func TestTableCellsKeepTheirDisplay(t *testing.T) {
94 t.Parallel()
95 bad := nonTableCellClasses(t)
96 files, err := fs.Glob(templateFS, "templates/*.html")
97 if err != nil {
98 t.Fatal(err)
99 }
100 for _, name := range files {
101 body, err := fs.ReadFile(templateFS, name)
102 if err != nil {
103 t.Fatal(err)
104 }
105 for _, cell := range cellClass.FindAllStringSubmatch(string(body), -1) {
106 for _, class := range strings.Fields(cell[1]) {
107 if display, ok := bad[class]; ok {
108 t.Errorf("%s: a td or th carries class %q (%s), which stops it being a table cell; wrap that element in a div inside the cell", name, class, display)
109 }
110 }
111 }
112 }
113 }