Skip to content

Commit

Permalink
fix: colspans for all cells
Browse files Browse the repository at this point in the history
  • Loading branch information
maxakuru committed Oct 11, 2023
1 parent 820ed12 commit 9ef9180
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions worker/src/util/adoc2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,15 @@ class FranklinConverter implements AdocTypes.Converter {
}

tableToTableBlock(node: AdocTypes.Table): string {
let colSpans = (
node.getHeadRows()[0]
?? node.getBodyRows()[0]
?? []
).map((col) => col.getColumnSpan() || '1');

if (!colSpans.some((c) => c !== '1')) {
const { head, body, foot } = node.getRows();
// 2D array of cell colspans
let colSpans: number[][] = ([
...head,
...body,
...foot,
]).map((row) => row.map((col) => col.getColumnSpan() || 1));

if (!colSpans.some((row) => row.some((col) => col !== 1))) {
colSpans = undefined;
}

Expand All @@ -360,7 +362,7 @@ class FranklinConverter implements AdocTypes.Converter {

return this.tableToBlock('table', node, {
preRows: `${colSpans
? /* html */`<div><div>col-spans</div><div>${colSpans.join(',')}</div></div>`
? /* html */`<div><div>col-spans</div><div>${colSpans.map((row) => row.join(',')).join(';')}</div></div>`
: ''}`
+ `${colWidths
? /* html */`<div><div>col-widths</div><div>${colWidths.join(',')}</div></div>`
Expand Down

0 comments on commit 9ef9180

Please sign in to comment.