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) <noreply@anthropic.com>

* Remove lookbehind in regex

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom MoorandClaude Opus 5 authored and GitHub committed 2026-08-15 16:29:17 -04:00
1 parent 6fe36aaea4
commit 60089edac8
3 files changed
+25 -3

No files matched your search

+13 -1
View File
@@ -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("<img");
}
/**
* Checks if the HTML string contains a table. The plain text alternative on the
* clipboard cannot describe a table, so the HTML must be parsed instead.
*
* @param html The HTML string to check.
* @returns True if the HTML string contains a table.
*/
function isContainingTable(html: string): boolean {
return html?.includes("<table");
}
function sliceSingleNode(slice: Slice) {
return slice.openStart === 0 &&
slice.openEnd === 0 &&
+9
View File
@@ -33,6 +33,15 @@ $1.00`)
).toBe(false);
});
it("returns false for currency amounts on a single line", () => {
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(`\`\`\`
+3 -2
View File
@@ -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;
}