diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.tsx b/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.tsx index 2b9e0bf645..aea3bddb4d 100644 --- a/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.tsx +++ b/packages/cli/src/ui/utils/InlineMarkdownRenderer.test.tsx @@ -1,6 +1,6 @@ /** * @license - * Copyright 2025 Google LLC + * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ @@ -21,6 +21,8 @@ describe('InlineMarkdownRenderer', () => { ['compile-time**', 14], ['$\\rightarrow$', 1], ['Sign Out $\\rightarrow$ Sign In', 18], + ['[Google](https://google.com)', 27], + ['Preceding [Link](url)', 20], ])( 'should measure markdown text length correctly for "%s"', (input, expected) => { diff --git a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx index dcba8bf80e..c4fbffade6 100644 --- a/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx +++ b/packages/cli/src/ui/utils/InlineMarkdownRenderer.tsx @@ -1,6 +1,6 @@ /** * @license - * Copyright 2025 Google LLC + * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ @@ -18,6 +18,13 @@ const INLINE_CODE_MARKER_LENGTH = 1; // For "`" const UNDERLINE_TAG_START_LENGTH = 3; // For "" const UNDERLINE_TAG_END_LENGTH = 4; // For "" +const LATEX_MAP: Record = { + '$\\rightarrow$': '→', + '$\\leftarrow$': '←', + '$\\uparrow$': '↑', + '$\\downarrow$': '↓', +}; + interface RenderInlineProps { text: string; defaultColor?: string; @@ -144,13 +151,7 @@ const RenderInlineInternal: React.FC = ({ ); } else if (fullMatch.startsWith('$') && fullMatch.endsWith('$')) { - const latexMap: Record = { - '$\\rightarrow$': '→', - '$\\leftarrow$': '←', - '$\\uparrow$': '↑', - '$\\downarrow$': '↓', - }; - const replacement = latexMap[fullMatch]; + const replacement = LATEX_MAP[fullMatch]; if (replacement) { renderedNode = ( @@ -199,7 +200,10 @@ export const getPlainTextLength = (text: string): number => { .replace(/~~(.*?)~~/g, '$1') .replace(/`(.*?)`/g, '$1') .replace(/(.*?)<\/u>/g, '$1') - .replace(/.*\[(.*?)\]\(.*\)/g, '$1') - .replace(/\$\\(rightarrow|leftarrow|uparrow|downarrow)\$/g, '→'); + .replace(/\[(.*?)\]\((.*?)\)/g, '$1 ($2)') + .replace( + /\$\\(rightarrow|leftarrow|uparrow|downarrow)\$/g, + (match) => LATEX_MAP[match] ?? match, + ); return stringWidth(cleanText); };