Show stage labels as literal Markdown text

This commit is contained in:
2026-11-10 20:24:18 +00:00
parent bae96e5dd5
commit a0e45c8f92
3 changed files with 41 additions and 7 deletions

View File

@@ -48,11 +48,11 @@ func Markdown(snapshot Snapshot, secrets ...string) []byte {
fmt.Fprintln(&b, "## Work-unit errors")
fmt.Fprintln(&b)
writeMatrix(&b, snapshot, safe, false)
writeMatrix(&b, snapshot, r, false)
fmt.Fprintln(&b)
fmt.Fprintln(&b, "## Recoveries")
fmt.Fprintln(&b)
writeMatrix(&b, snapshot, safe, true)
writeMatrix(&b, snapshot, r, true)
fmt.Fprintln(&b)
fmt.Fprintln(&b, "Legend: `—` = not started; `n*` = interrupted with n recorded errors or recoveries. Completed error cells are 0 or 1.")
fmt.Fprintln(&b)
@@ -71,7 +71,7 @@ func showCount(value *int) string {
return fmt.Sprint(*value)
}
func writeMatrix(b *strings.Builder, snapshot Snapshot, safe func(string) string, recovery bool) {
func writeMatrix(b *strings.Builder, snapshot Snapshot, redactor redaction.Redactor, recovery bool) {
if len(snapshot.StageNames) == 0 || len(snapshot.WorkUnits) == 0 {
fmt.Fprintln(b, "No work units.")
return
@@ -79,7 +79,7 @@ func writeMatrix(b *strings.Builder, snapshot Snapshot, safe func(string) string
columns := snapshot.StageNames
fmt.Fprint(b, "| Chunk |")
for _, name := range columns {
fmt.Fprintf(b, " %s |", safe(name))
fmt.Fprintf(b, " %s |", stageCellEscaper.Replace(html.EscapeString(redactor.String(name))))
}
fmt.Fprint(b, "\n| --- |")
for range columns {
@@ -120,6 +120,14 @@ func writeMatrix(b *strings.Builder, snapshot Snapshot, safe func(string) string
}
}
// Encode input backslashes so they cannot interfere with Markdown escapes.
var stageCellEscaper = strings.NewReplacer(
"\r\n", "<br>", "\r", "<br>", "\n", "<br>",
"\\", "&#92;", "|", "\\|", "`", "\\`",
"[", "\\[", "]", "\\]", "*", "\\*", "_", "\\_", "~", "\\~",
"://", "&#58;//", "www.", "www&#46;", "@", "&#64;",
)
func writeReasons(b *strings.Builder, title string, counts map[string]int, safe func(string) string) {
fmt.Fprintf(b, "### %s\n\n", title)
if len(counts) == 0 {