Skip to content

fix(cli): align table rows containing inline markdown#20359

Closed
dlezama wants to merge 3 commits intogoogle-gemini:mainfrom
Blue-Origin:fix/table-inline-markdown-alignment
Closed

fix(cli): align table rows containing inline markdown#20359
dlezama wants to merge 3 commits intogoogle-gemini:mainfrom
Blue-Origin:fix/table-inline-markdown-alignment

Conversation

@dlezama
Copy link

@dlezama dlezama commented Feb 25, 2026

Summary

Fix table row misalignment when cells contain inline markdown (backticks, bold, strikethrough, etc.). Rows with inline code like `/help` rendered 2 characters narrower than plain-text rows because TableRenderer measured width including markdown markers that RenderInline strips during rendering.

Details

Root cause: renderCell() in TableRenderer used styledCharsWidth on raw cell text (e.g., `/help` = 7 chars) to calculate padding. But RenderInline strips the backticks and renders /help (5 chars). The padding was 2 chars too small per backtick pair, causing visible misalignment in the right border.

Fix: Extract parseInlineMarkdown() as a shared parser returning typed MarkdownSegment[] segments. Both RenderInline (React nodes) and the new stripInlineMarkdown() (plain text projection) consume these segments. TableRenderer now uses stripInlineMarkdown to compute the actual rendered width for padding calculation.

This eliminates the previous duplication concern — the parsing logic exists in exactly one place.

Files changed:

  • InlineMarkdownRenderer.tsx — Refactored: extracted parseInlineMarkdown() shared parser, RenderInline now maps segments to React nodes, added stripInlineMarkdown() for plain-text width measurement
  • TableRenderer.tsxrenderCell() uses stripInlineMarkdown for accurate displayWidth
  • InlineMarkdownRenderer.test.tsx — New: 29 tests covering parser, strip function, and component rendering
  • TableRenderer.test.tsx — Added 2 regression tests for inline markdown alignment

Related Issues

How to Validate

  1. Run the new regression tests:
    npm test -w @google/gemini-cli -- src/ui/utils/TableRenderer.test.tsx -t "inline"
    npm test -w @google/gemini-cli -- src/ui/utils/InlineMarkdownRenderer.test.tsx
  2. Run the full TableRenderer test suite (17 tests, all existing snapshots unchanged):
    npm test -w @google/gemini-cli -- src/ui/utils/TableRenderer.test.tsx
  3. To reproduce the original bug, revert the TableRenderer.tsx change and run the "backtick-wrapped inline code" test — it will fail with rows at width 49 vs 51.
  4. Visually: ask the model to produce a markdown table with backtick-wrapped content in cells. All rows should now align.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

TableRenderer measured cell width including markdown markers (backticks,
bold **, strikethrough ~~, etc.) but RenderInline strips those markers
when rendering. This caused rows with inline code like `/help` to be
visually narrower than rows with plain text.

Extract parseInlineMarkdown() as a shared parser that both RenderInline
(React nodes) and the new stripInlineMarkdown() (plain text projection)
consume. TableRenderer now uses stripInlineMarkdown to compute the
actual rendered width for padding, keeping all rows aligned.
@dlezama dlezama requested a review from a team as a code owner February 25, 2026 22:41
@google-cla
Copy link

google-cla bot commented Feb 25, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dlezama, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a visual bug in the CLI's table rendering where rows containing inline markdown would appear misaligned. The solution involves centralizing the logic for parsing inline markdown, allowing for consistent interpretation across both rendering and plain-text width calculation. This ensures that tables are displayed correctly, regardless of the markdown content within their cells, significantly improving the user interface's consistency and readability.

Highlights

  • Table Row Misalignment Fix: Resolved an issue where table rows containing inline markdown (e.g., backticks, bold) were misaligned because the TableRenderer incorrectly measured their width.
  • Centralized Markdown Parsing: Introduced a new parseInlineMarkdown() function that acts as a single source of truth for classifying inline markdown into typed segments, eliminating parsing duplication.
  • Accurate Width Calculation: Implemented stripInlineMarkdown() to provide a plain-text projection of markdown, which TableRenderer now uses to accurately calculate cell widths for correct padding.
  • Refactored Inline Renderer: The RenderInline component was refactored to consume the new MarkdownSegment[] from parseInlineMarkdown(), simplifying its rendering logic.
  • Comprehensive Testing: Added extensive unit tests for the new markdown parsing and stripping functions, along with regression tests for TableRenderer to ensure proper alignment with inline markdown.
Changelog
  • packages/cli/src/ui/utils/InlineMarkdownRenderer.test.tsx
    • Added new test file to cover parseInlineMarkdown, stripInlineMarkdown, and RenderInline functionality.
  • packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx
    • Introduced parseInlineMarkdown function and MarkdownSegment type for unified markdown parsing.
    • Refactored RenderInline component to utilize the new parseInlineMarkdown for rendering.
    • Added stripInlineMarkdown function to remove markdown markers for accurate text width measurement.
  • packages/cli/src/ui/utils/TableRenderer.test.tsx
    • Added two regression tests to verify correct table alignment with inline code and mixed markdown.
  • packages/cli/src/ui/utils/TableRenderer.tsx
    • Imported stripInlineMarkdown for use in cell width calculations.
    • Updated renderCell to use stripInlineMarkdown for displayWidth calculation, ensuring proper padding.
  • packages/cli/src/ui/utils/snapshots/InlineMarkdownRenderer.test.tsx.snap
    • Updated snapshot tests to reflect changes in RenderInline component's output.
Activity
  • The author has validated the changes on Linux using npm run.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the table alignment issue caused by inline markdown. The refactoring of the markdown parsing logic into a centralized parseInlineMarkdown function is a great improvement for maintainability. I've added one comment regarding a potential edge case in the new parser's logic for handling code spans, emphasizing the need for robust input handling.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 25, 2026
Damian Lezama added 2 commits February 25, 2026 15:04
…rkdown-alignment

# Conflicts:
#	packages/cli/src/ui/utils/TableRenderer.tsx
Replace the regex-based code span matcher (`+.+?`+) with a dedicated
scanCodeSpan function that counts the opening backtick run length and
scans for a closing run of exactly the same length. This correctly
handles cases like ``a`b`` (content: a`b) and ```a``b```
(content: a``b) where the previous regex would match only the first
backtick pair and fall back to plain text.

The scanner is interleaved with the existing INLINE_REGEX: at each
position, backticks are checked first (code spans have highest priority
in CommonMark), then the regex handles other inline markers.

Add 5 tests covering double- and triple-backtick code spans with
embedded backticks for both parseInlineMarkdown and stripInlineMarkdown.
@dlezama dlezama force-pushed the fix/table-inline-markdown-alignment branch from 874fd92 to c1dbc78 Compare February 25, 2026 23:29
@jacob314
Copy link
Contributor

Thanks for your PR. However there is already an in-progress fix for this.
#20042

Feel free to test and help review that PR.

@jacob314 jacob314 closed this Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants