tui: avoid table detection for pipe prose (#17424)

This commit is contained in:
Parth Sareen 2026-07-27 13:42:08 -07:00 committed by GitHub
parent eec8e0b945
commit bf7be180e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

View file

@ -387,8 +387,10 @@ func isMarkdownTableSeparator(line string) bool {
return false
}
for _, cell := range cells {
cell = strings.Trim(cell, " :-")
if cell != "" {
cell = strings.TrimSpace(cell)
cell = strings.TrimPrefix(cell, ":")
cell = strings.TrimSuffix(cell, ":")
if cell == "" || strings.Trim(cell, "-") != "" {
return false
}
}

View file

@ -2075,3 +2075,39 @@ func TestRenderMarkdownTableWrapsLongCells(t *testing.T) {
}
}
}
func TestRenderMarkdownProseWithPipeExamplesIsNotTable(t *testing.T) {
markdown := strings.Join([]string{
"- **Regression confirmed** vs. `fdbe8d33`: the bare `< | open | >` remains prose.",
"| | |",
"- **Severity**: `< | close | >` is another inline example.",
}, "\n")
rendered := renderMarkdownForView(markdown, 120)
plain := stripANSI(rendered)
if !strings.Contains(plain, "| | |") || !strings.Contains(plain, "the bare < | open | > remains") || !strings.Contains(plain, "< | close | > is another") {
t.Fatalf("pipe-delimited prose rendered as a table:\n%s", plain)
}
if !strings.Contains(rendered, chatStrongStyle.Render("Regression confirmed")) {
t.Fatalf("bold prose was not emphasized: %q", rendered)
}
if !strings.Contains(rendered, chatInlineCodeStyle.Render("fdbe8d33")) {
t.Fatalf("inline code was not styled: %q", rendered)
}
}
func TestRenderMarkdownTablePreservesValidSeparator(t *testing.T) {
markdown := strings.Join([]string{
"| Name | State |",
"| --- | :---: |",
"| Ollama | Ready |",
}, "\n")
plain := stripANSI(renderMarkdownForView(markdown, 80))
if strings.Contains(plain, "---") {
t.Fatalf("table separator should not render as prose:\n%s", plain)
}
if !strings.Contains(plain, "Name") || !strings.Contains(plain, "Ollama") {
t.Fatalf("valid Markdown table was not rendered:\n%s", plain)
}
}