Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 1x 84x 170x 84x 170x 335x 335x 335x 354x 377x 377x 170x 377x 84x | import { toArray } from '../toArray';
import type { ParsedTable } from 'roosterjs-content-model-types';
/**
* Parse a table into a two dimensions array of TD elements. For those merged cells, the value will be null.
* @param table Input HTML Table element
* @returns Array of TD elements
*/
export function parseTableCells(table: HTMLTableElement): ParsedTable {
const trs = toArray(table.rows);
const cells: ParsedTable = trs.map(row => []);
trs.forEach((tr, rowIndex) => {
for (let sourceCol = 0, targetCol = 0; sourceCol < tr.cells.length; sourceCol++) {
// Skip the cells which already initialized
for (; cells[rowIndex][targetCol] !== undefined; targetCol++) {}
const td = tr.cells[sourceCol];
for (let colSpan = 0; colSpan < td.colSpan; colSpan++, targetCol++) {
for (let rowSpan = 0; rowSpan < td.rowSpan; rowSpan++) {
Eif (cells[rowIndex + rowSpan]) {
cells[rowIndex + rowSpan][targetCol] =
colSpan == 0
? rowSpan == 0
? td
: 'spanTop'
: rowSpan == 0
? 'spanLeft'
: 'spanBoth';
}
}
}
}
for (let col = 0; col < cells[rowIndex].length; col++) {
cells[rowIndex][col] = cells[rowIndex][col] || null;
}
});
return cells;
}
|