fix(ui): misaligned markdown table rendering (#8336)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Sudheer Tripathi
2025-12-02 04:56:48 +05:30
committed by GitHub
parent 5fa6d87c25
commit 70a48a3dd6
2 changed files with 26 additions and 1 deletions

View File

@@ -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);
},
);
});

View File

@@ -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')