From 2aaa89a476da4e0edec36a6bb3047ac6ff4bd791 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Oct 2026 00:33:16 +0300 Subject: [PATCH] fix(copy-page): scope table cell queries to direct children --- src/components/CopyPageButton/CopyPageButton.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/CopyPageButton/CopyPageButton.jsx b/src/components/CopyPageButton/CopyPageButton.jsx index a8d3555c279..d7f3b7bfc4b 100644 --- a/src/components/CopyPageButton/CopyPageButton.jsx +++ b/src/components/CopyPageButton/CopyPageButton.jsx @@ -56,7 +56,7 @@ const tableToMarkdown = tableEl => { ) if (rows.length === 0) return '' - const firstRowCells = Array.from(rows[0].querySelectorAll('th, td')) + const firstRowCells = Array.from(rows[0].querySelectorAll(':scope > th, :scope > td')) const headers = firstRowCells.map(cell => cell.textContent.trim()) let md = '' @@ -67,7 +67,12 @@ const tableToMarkdown = tableEl => { const bodyRows = rows.slice(1) bodyRows.forEach(tr => { - const cells = Array.from(tr.querySelectorAll('th, td')).map(td => td.textContent.trim()) + // `:scope` is required so cells belonging to a table nested inside a cell + // (for example a Markdown table used inside a table cell) are not pulled + // into the outer row and shift every following column. + const cells = Array.from(tr.querySelectorAll(':scope > th, :scope > td')).map(td => + td.textContent.trim() + ) md += `| ${cells.join(' | ')} |\n` })