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; }