Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/CopyPageButton/CopyPageButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''

Expand All @@ -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`
})

Expand Down