From 70a48a3dd6620aefb8b998c48b84f83a67a0edcb Mon Sep 17 00:00:00 2001 From: Sudheer Tripathi <31629433+dumbbellcode@users.noreply.github.com> Date: Tue, 2 Dec 2025 04:56:48 +0530 Subject: [PATCH] fix(ui): misaligned markdown table rendering (#8336) Co-authored-by: Tommaso Sciortino --- .../ui/utils/InlineMarkdownRenderer.test.ts | 25 +++++++++++++++++++ .../src/ui/utils/InlineMarkdownRenderer.tsx | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts b/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts new file mode 100644 index 0000000000..11fb6d56eb --- /dev/null +++ b/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.ts @@ -0,0 +1,25 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { getPlainTextLength } from './InlineMarkdownRenderer.js'; +import { describe, it, expect } from 'vitest'; + +describe('getPlainTextLength', () => { + it.each([ + ['**Primary Go', 12], + ['*Primary Go', 11], + ['**Primary Go**', 10], + ['*Primary Go*', 10], + ['**', 2], + ['*', 1], + ['compile-time**', 14], + ])( + 'should measure markdown text length correctly for "%s"', + (input, expected) => { + expect(getPlainTextLength(input)).toBe(expected); + }, + ); +}); diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx index 1b35c62bcc..370b03d6f5 100644 --- a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx +++ b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx @@ -178,7 +178,7 @@ export const RenderInline = React.memo(RenderInlineInternal); export const getPlainTextLength = (text: string): number => { const cleanText = text .replace(/\*\*(.*?)\*\*/g, '$1') - .replace(/\*(.*?)\*/g, '$1') + .replace(/\*(.+?)\*/g, '$1') .replace(/_(.*?)_/g, '$1') .replace(/~~(.*?)~~/g, '$1') .replace(/`(.*?)`/g, '$1')