From 60089edac830732977b4673504c25e79ba66ea6d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 15 Aug 2026 16:29:17 -0400 Subject: [PATCH] fix: Pasting a table from Google Sheets does not create a table (#13443) * fix: Pasting a table from Google Sheets does not create a table Spreadsheet cells containing currency amounts caused isMarkdown to misread the tab-separated plain text flavour of the clipboard as inline LaTeX, so the paste handler discarded the HTML table and reparsed the text as Markdown. Tighten the LaTeX heuristic to require delimiters that hug their content and a closing delimiter not followed by a digit, and always prefer the HTML parser when the clipboard HTML contains a table. Co-Authored-By: Claude Opus 5 (1M context) * Remove lookbehind in regex --------- Co-authored-by: Claude Opus 5 (1M context) --- app/editor/extensions/PasteHandler.tsx | 14 +++++++++++++- shared/editor/lib/isMarkdown.test.ts | 9 +++++++++ shared/editor/lib/isMarkdown.ts | 5 +++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/editor/extensions/PasteHandler.tsx b/app/editor/extensions/PasteHandler.tsx index ca781d0ed0..1230ba0b72 100644 --- a/app/editor/extensions/PasteHandler.tsx +++ b/app/editor/extensions/PasteHandler.tsx @@ -274,7 +274,8 @@ export default class PasteHandler extends Extension { if ( (isMarkdown(text) && !isDropboxPaper(html) && - !isContainingImage(html)) || + !isContainingImage(html) && + !isContainingTable(html)) || pasteCodeLanguage === "markdown" || this.shiftKey || !html @@ -633,6 +634,17 @@ function isContainingImage(html: string): boolean { return html?.includes(" { + expect(isMarkdown(`-$187.55\t-$91.93`)).toBe(false); + expect( + isMarkdown(`-$187.55\t-$91.93 +-$2,222.97\t-$4,109.98`) + ).toBe(false); + expect(isMarkdown(`It costs $10 or $20`)).toBe(false); +}); + test("returns false for non-closed fence", () => { expect( isMarkdown(`\`\`\` diff --git a/shared/editor/lib/isMarkdown.ts b/shared/editor/lib/isMarkdown.ts index 1adc61c3ea..830086cc7d 100644 --- a/shared/editor/lib/isMarkdown.ts +++ b/shared/editor/lib/isMarkdown.ts @@ -9,8 +9,9 @@ export default function isMarkdown(text: string): boolean { signals += fences.length; } - // latex-ish - const latex = text.match(/\$(.+)\$/g); + // latex-ish, the delimiters must hug their content and the closing one must + // not be followed by a digit so that currency amounts are not counted. + const latex = text.match(/\$[^\s](?:.*?[^\s])?\$(?!\d)/g); if (latex && latex.length > 0) { signals += latex.length; }