fix(tui): tighten fence indent and sparse spillover detection

This commit is contained in:
Felipe Coury
2026-04-06 13:19:49 -03:00
committed by Felipe Coury
parent de9c17d1e2
commit 75f05c8bda
3 changed files with 59 additions and 2 deletions
+19 -1
View File
@@ -1426,7 +1426,25 @@ where
}
fn looks_like_html_content(text: &str) -> bool {
text.contains('<') && text.contains('>')
let bytes = text.as_bytes();
for idx in 0..bytes.len() {
if bytes[idx] != b'<' {
continue;
}
let mut tag_start = idx + 1;
if tag_start < bytes.len() && (bytes[tag_start] == b'/' || bytes[tag_start] == b'!') {
tag_start += 1;
}
if tag_start < bytes.len()
&& bytes[tag_start].is_ascii_alphabetic()
&& bytes[tag_start + 1..].contains(&b'>')
{
return true;
}
}
false
}
fn looks_like_html_label_line(text: &str) -> bool {
+22
View File
@@ -1542,6 +1542,28 @@ fn table_spillover_prose_wraps_in_narrow_width() {
);
}
#[test]
fn table_keeps_sparse_comparison_row_inside_grid() {
let md = "| A | B | C |\n|---|---|---|\n| x < y > z | | |\n";
let text = render_markdown_text(md);
let lines: Vec<String> = text
.lines
.iter()
.map(|line| line.spans.iter().map(|span| span.content.clone()).collect())
.collect();
assert!(
lines
.iter()
.any(|line| line.contains("│ x < y > z") && line.ends_with('│')),
"expected sparse comparison row to remain inside table grid: {lines:?}"
);
assert!(
!lines.iter().any(|line| line.trim() == "x < y > z"),
"did not expect sparse comparison row to spill outside table: {lines:?}"
);
}
#[test]
fn table_keeps_sparse_rows_with_empty_trailing_cells() {
let md = "| A | B | C |\n|---|---|---|\n| a | | |\n";
+18 -1
View File
@@ -616,7 +616,15 @@ fn parse_lines_with_fence_state(source: &str) -> Vec<ParsedLine<'_>> {
},
});
let trimmed = raw_line.trim_start();
let leading_spaces = raw_line
.as_bytes()
.iter()
.take_while(|byte| **byte == b' ')
.count();
if leading_spaces > 3 {
continue;
}
let trimmed = &raw_line[leading_spaces..];
if let Some((marker, len)) = parse_fence_marker(trimmed) {
if !in_fence {
in_fence = true;
@@ -1391,6 +1399,15 @@ mod tests {
);
}
#[test]
fn table_holdback_state_treats_indented_fence_text_as_plain_content() {
let source = " ```sh\n| Key | Description |\n| --- | --- |\n";
assert!(
matches!(table_holdback_state(source), TableHoldbackState::Confirmed),
"indented fence-like text should not open a fence and should not block table detection",
);
}
// -----------------------------------------------------------------------
// source_bytes_for_rendered_count — prefix-stability tests
// -----------------------------------------------------------------------