From 986ca19516e0b6b0b0a961e07f0f135a5292a827 Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Sat, 25 Oct 2025 20:09:56 +0200 Subject: [PATCH] markdown: Fix HTML tables with mismatching columns (#41108) Follow-up: https://github.com/zed-industries/zed/pull/39898 Right now, we don't fill the empty column when the current row count is less than the max row count. This PR fixes that by filling it with an empty cell. So the table columns don't flow in the wrong direction, as you can see inside the first screenshot. **Before** Screenshot 2025-10-24 at 16 09 02 **After** Screenshot 2025-10-24 at 16 19 17 **Code example** ```html // extra column here
Region Revenue Growth
Q2 2024 Q3 2024
North America $2.8M $2.4B +85,614% +99%
Europe $1.2M $1.9B +158,233%
Asia-Pacific $0.5M $1.4B +279,900%
``` **Note** there are no release notes, as the previous PR didn't get released yet. Release Notes: - N/A --- .../markdown_preview/src/markdown_renderer.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/markdown_preview/src/markdown_renderer.rs b/crates/markdown_preview/src/markdown_renderer.rs index 0abb12015af317702ff3afd853eab74a40817941..c6f4354423e927fba64294f2f581faf1f4356a5d 100644 --- a/crates/markdown_preview/src/markdown_renderer.rs +++ b/crates/markdown_preview/src/markdown_renderer.rs @@ -553,6 +553,23 @@ fn render_markdown_table(parsed: &ParsedMarkdownTable, cx: &mut RenderContext) - col_idx += cell.col_span; } + + // Fill remaining columns with empty cells if needed + while col_idx < max_column_count { + if grid_occupied[row_idx][col_idx] { + col_idx += 1; + continue; + } + + let empty_cell = div() + .border_1() + .size_full() + .border_color(cx.border_color) + .when(row_idx % 2 == 1, |this| this.bg(cx.panel_background_color)); + + cells.push(empty_cell); + col_idx += 1; + } } cx.with_common_p(div())