mirror of
https://github.com/openai/codex.git
synced 2026-11-01 19:33:35 +00:00
fix(tui): restore boxed markdown tables with emoji content
This commit is contained in:
committed by
Felipe Coury
parent
1a031ee706
commit
f038bb5c74
@@ -981,21 +981,6 @@ where
|
||||
Self::normalize_row(row, column_count);
|
||||
}
|
||||
|
||||
if Self::table_contains_width_unstable_symbols(&header, &rows) {
|
||||
return RenderedTableLines {
|
||||
table_lines: self.render_table_pipe_fallback(
|
||||
&header,
|
||||
&rows,
|
||||
&table_state.alignments,
|
||||
),
|
||||
table_lines_prewrapped: false,
|
||||
spillover_lines: spillover_rows
|
||||
.into_iter()
|
||||
.flat_map(|spillover| spillover.lines)
|
||||
.collect(),
|
||||
};
|
||||
}
|
||||
|
||||
let available_width = self.available_table_width(column_count);
|
||||
let widths =
|
||||
self.compute_column_widths(&header, &rows, &table_state.alignments, available_width);
|
||||
@@ -1394,35 +1379,6 @@ where
|
||||
wrapped
|
||||
}
|
||||
|
||||
fn table_contains_width_unstable_symbols(
|
||||
header: &[TableCell],
|
||||
rows: &[Vec<TableCell>],
|
||||
) -> bool {
|
||||
header
|
||||
.iter()
|
||||
.any(Self::cell_contains_width_unstable_symbols)
|
||||
|| rows
|
||||
.iter()
|
||||
.flatten()
|
||||
.any(Self::cell_contains_width_unstable_symbols)
|
||||
}
|
||||
|
||||
fn cell_contains_width_unstable_symbols(cell: &TableCell) -> bool {
|
||||
cell.lines
|
||||
.iter()
|
||||
.flat_map(|line| line.spans.iter())
|
||||
.flat_map(|span| span.content.chars())
|
||||
.any(Self::is_width_unstable_symbol)
|
||||
}
|
||||
|
||||
/// Symbols that frequently render with platform-dependent width in
|
||||
/// terminals (emoji and variation-selector sequences).
|
||||
fn is_width_unstable_symbol(ch: char) -> bool {
|
||||
matches!(ch, '\u{200D}' | '\u{20E3}' | '\u{FE0E}' | '\u{FE0F}')
|
||||
|| ('\u{2600}'..='\u{27BF}').contains(&ch)
|
||||
|| ('\u{1F300}'..='\u{1FAFF}').contains(&ch)
|
||||
}
|
||||
|
||||
/// Detect rows that are artifacts of pulldown-cmark's lenient table parsing.
|
||||
///
|
||||
/// pulldown-cmark accepts body rows without leading pipes, which can absorb a
|
||||
|
||||
@@ -1448,7 +1448,7 @@ fn escaped_pipes_render_in_table_cells() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_with_emoji_cells_uses_pipe_fallback_for_stable_alignment() {
|
||||
fn table_with_emoji_cells_renders_boxed_table() {
|
||||
let md = "| Task | State |\n|---|---|\n| Unit tests | ✅ |\n| Release notes | 📝 |\n";
|
||||
let text = crate::markdown_render::render_markdown_text_with_width(md, Some(80));
|
||||
let lines: Vec<String> = text
|
||||
@@ -1457,12 +1457,12 @@ fn table_with_emoji_cells_uses_pipe_fallback_for_stable_alignment() {
|
||||
.map(|line| line.spans.iter().map(|span| span.content.clone()).collect())
|
||||
.collect();
|
||||
assert!(
|
||||
lines.first().is_some_and(|line| line.starts_with('|')),
|
||||
"expected pipe-table fallback for emoji content: {lines:?}"
|
||||
lines.iter().any(|line| line.contains('┌')),
|
||||
"expected boxed table for emoji content: {lines:?}"
|
||||
);
|
||||
assert!(
|
||||
!lines.iter().any(|line| line.contains('┌')),
|
||||
"did not expect box-drawing table for emoji content: {lines:?}"
|
||||
!lines.iter().any(|line| line.starts_with("|:---")),
|
||||
"did not expect pipe-delimiter fallback for emoji content: {lines:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user