Skip to content

Commit 74babad

Browse files
committed
fix(chat): classify inline-markdown tokens by split parity, require non-space emphasis boundaries
1 parent d688239 commit 74babad

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/inline-markdown.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ describe('renderInlineMarkdown', () => {
7373
expect(renderInlineMarkdown('2 * 3 * 4')).toEqual(['2 * 3 * 4'])
7474
})
7575

76+
it('never reclassifies plain text the tokenizer rejected', () => {
77+
expect(renderInlineMarkdown('* x *')).toEqual(['* x *'])
78+
expect(renderInlineMarkdown('** spaced bullets **')).toEqual(['** spaced bullets **'])
79+
})
80+
7681
it('passes plain text through untouched', () => {
7782
expect(renderInlineMarkdown('no markup here.')).toEqual(['no markup here.'])
7883
})

apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/inline-markdown.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Fragment, type ReactNode } from 'react'
22

33
const INLINE_TOKEN =
4-
/(\*{3}[^*\n]+\*{3}|\*\*[^*\n]+\*\*|\*[^\s*](?:[^*\n]*[^\s*])?\*|`[^`\n]+`|\[[^\]\n]+\]\([^\s)]+\))/g
4+
/(\*{3}[^\s*](?:[^*\n]*[^\s*])?\*{3}|\*\*[^\s*](?:[^*\n]*[^\s*])?\*\*|\*[^\s*](?:[^*\n]*[^\s*])?\*|`[^`\n]+`|\[[^\]\n]+\]\([^\s)]+\))/g
55

66
const LINK_TOKEN = /^\[([^\]\n]+)\]\([^\s)]+\)$/
77

@@ -13,9 +13,14 @@ const LINK_TOKEN = /^\[([^\]\n]+)\]\([^\s)]+\)$/
1313
* nested markers resolve; code spans stay verbatim. Everything else,
1414
* including unterminated markers, renders as-is. Full Streamdown rendering is
1515
* intentionally avoided here — these rows re-render on every streaming frame.
16+
*
17+
* Splitting on a single capturing group alternates plain text (even indices)
18+
* and matched tokens (odd indices), so index parity is the exact
19+
* discriminator — plain text that merely resembles a marker (e.g. `* x *`,
20+
* rejected by the tokenizer's boundary rules) is never reclassified.
1621
*/
1722
export function renderInlineMarkdown(text: string): ReactNode[] {
18-
return text.split(INLINE_TOKEN).map(renderToken)
23+
return text.split(INLINE_TOKEN).map((part, i) => (i % 2 === 1 ? renderToken(part, i) : part))
1924
}
2025

2126
function renderToken(part: string, key: number): ReactNode {

0 commit comments

Comments
 (0)