diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts b/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts index bf1fafca2d..ec9e3bd7bd 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts +++ b/services/web/frontend/js/features/source-editor/extensions/visual/paste-html.ts @@ -53,7 +53,11 @@ export const pasteHtml = [ // fall back to creating a figure when there's an image on the clipoard, // unless the HTML indicates that it came from an Office application // (which also puts an image on the clipboard) - if (clipboardData.files.length > 0 && !hasProgId(documentElement)) { + if ( + clipboardData.files.length > 0 && + !hasProgId(documentElement) && + !isOnlyTable(documentElement) + ) { return false } @@ -135,6 +139,17 @@ const hasProgId = (documentElement: HTMLElement) => { return meta && meta.content.trim().length > 0 } +// detect a table (probably pasted from desktop Excel) +const isOnlyTable = (documentElement: HTMLElement) => { + const body = documentElement.querySelector('body') + + return ( + body && + body.childElementCount === 1 && + body.firstElementChild!.nodeName === 'TABLE' + ) +} + const htmlToLaTeX = (bodyElement: HTMLElement) => { // remove style elements removeUnwantedElements(bodyElement, 'style')