Skip to content

Commit 28296f0

Browse files
committed
fix(markdown): keep angle-bracket prose literal on paste
1 parent c12a669 commit 28296f0

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-parse.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ export function hasMarkdownFormatting(body: string): boolean {
226226
markdown.walkTokens(markdown.lexer(block), (token) => {
227227
// Native paste can add autolinks separately, retaining the text if formatting exceeds its budget.
228228
if (token.type === 'link' && token.raw === token.text) return
229+
// Bare HTML can be ordinary text such as List<Code>; explicit Markdown bypasses detection.
230+
if (token.type === 'html') return
229231
if (!['paragraph', 'text', 'space', 'escape', 'def'].includes(token.type)) formatted = true
230232
})
231233
if (formatted) return true

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-paste.test.ts‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ describe('markdown paste', () => {
9494
expect(editor.getText()).toBe('')
9595
})
9696

97+
it.each(['List<String>', 'List<Code>', 'Use <em> for emphasis'])(
98+
'preserves ordinary angle-bracket text %s on plain clipboard paste',
99+
(text) => {
100+
const editor = mount()
101+
dispatchPaste(editor, text)
102+
expect(editor.state.doc.textContent).toBe(text)
103+
expect(editor.getJSON().content?.[0].content).toEqual([{ type: 'text', text }])
104+
const reopened = mount()
105+
reopened.commands.setContent(editor.getMarkdown(), { contentType: 'markdown' })
106+
expect(reopened.getJSON()).toEqual(editor.getJSON())
107+
}
108+
)
109+
97110
it('does not flatten a rich table containing literal Markdown-shaped cell text', () => {
98111
const editor = mount()
99112
dispatchPaste(
@@ -137,14 +150,18 @@ describe('markdown paste', () => {
137150
}
138151
)
139152

140-
it.each(['Paste title', ''])(
153+
it.each([
154+
['Paste title', 'Paste title\n===========', '<h1>Paste title</h1>'],
155+
['', 'Paste title\n===========', '<h1>Paste title</h1>'],
156+
['HTML source', '<em>Declared emphasis</em>', '<em>Declared emphasis</em>'],
157+
])(
141158
'honors explicit Markdown provenance with plain fallback %j',
142-
(fallback) => {
159+
(fallback, markdown, expectedHtml) => {
143160
const editor = mount()
144161
dispatchPaste(editor, fallback, '<b>Wrong representation</b>', {
145-
'text/markdown': 'Paste title\n===========',
162+
'text/markdown': markdown,
146163
})
147-
expect(editor.getHTML()).toContain('<h1>Paste title</h1>')
164+
expect(editor.getHTML()).toContain(expectedHtml)
148165
expect(editor.getText()).not.toContain('Wrong representation')
149166
}
150167
)

‎apps/sim/scripts/test-markdown-viewer-e2e.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ async function provePastePersistence(page: Page, browserName: string) {
498498
await expect(
499499
editor.locator('pre').filter({ hasText: `const ${browserName}Clipboard` })
500500
).toContainText('"<literal>"')
501+
await paste({ 'text/plain': 'List<Code>' })
502+
const genericParagraph = editor.locator(':scope > p').filter({ hasText: /^List<Code>$/ })
503+
await expect(genericParagraph).toHaveCount(1)
501504
await paste(
502505
{ 'text/plain': `**${marker} literal**`, 'text/html': `<b>${marker} literal</b>` },
503506
true
@@ -522,6 +525,7 @@ async function provePastePersistence(page: Page, browserName: string) {
522525
)
523526
await expect(editor.locator(':scope > p').last()).toHaveText(`**${marker} literal**`)
524527
await contained(page)
528+
await expect(genericParagraph).toHaveCount(1)
525529
await page.screenshot({ path: resolve(artifactDir, `${browserName}-paste-reopened.png`) })
526530
const metadata = toRecord(
527531
toRecord(await (await request(`/api/workspaces/${workspaceId}/files/${pastedFileId}`)).json())
@@ -546,6 +550,7 @@ async function provePastePersistence(page: Page, browserName: string) {
546550
.poll(readPasteSource, { timeout: 30_000 })
547551
.toContain(`${marker} after external update`)
548552
const afterLocalEdit = await readPasteSource()
553+
await expect(genericParagraph).toHaveCount(1)
549554
assert(afterLocalEdit.includes(`## ${remoteMarker}`), 'Local edit lost the external update')
550555
assert(
551556
afterLocalEdit.includes(`${marker} measure<br>`),

0 commit comments

Comments
 (0)