Files
gabrielvidalandClaude Sonnet 5.5 94d3a3e872 feat(form): page support for conditions, list, rating, time, daterange, diff, details
The answer page draws the new fields and runs the conditions: showIf hides a
field and what tests it (and a page left empty), requiredIf turns the
required marker on, a list adds and removes rows, a draft keeps its rows.
Every one of them still posts and validates with JavaScript off. A
review-change example uses them all.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 19:33:34 +01:00

36 lines
1.1 KiB
Go

package form
import (
"html"
"html/template"
"strings"
)
// DiffHTML draws a unified diff for a phone: one line per row, added and
// removed lines tinted, file headers and hunk markers set apart. It needs no
// script, and everything is escaped.
func DiffHTML(src string) template.HTML {
var b strings.Builder
lines := strings.Split(strings.ReplaceAll(strings.TrimRight(src, "\r\n"), "\r\n", "\n"), "\n")
for _, l := range lines {
class := "d-ctx"
switch {
case strings.HasPrefix(l, "+++") || strings.HasPrefix(l, "---"):
class = "d-file"
case strings.HasPrefix(l, "@@"):
class = "d-hunk"
case strings.HasPrefix(l, "diff ") || strings.HasPrefix(l, "index ") || strings.HasPrefix(l, "new file") ||
strings.HasPrefix(l, "deleted file") || strings.HasPrefix(l, "rename ") || strings.HasPrefix(l, "similarity "):
class = "d-meta"
case strings.HasPrefix(l, "+"):
class = "d-add"
case strings.HasPrefix(l, "-"):
class = "d-del"
}
b.WriteString(`<span class="` + class + `">`)
b.WriteString(html.EscapeString(l))
b.WriteString("</span>")
}
return template.HTML(b.String())
}