Skip to content

Commit 8ad0330

Browse files
authored
Merge pull request #69 from contentstack/fix/DX-700-table-rowspan-colspan
fix: adds rowspan and colspan to th and td node
2 parents 92a5651 + 5615287 commit 8ad0330

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

__test__/default-node-options.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ const embedNodeWithURL: Node = {
5151
children: []
5252
}
5353

54+
const tableDataNode: Node = {
55+
type: NodeType.TABLE_DATA,
56+
attrs: {
57+
rowSpan: 2,
58+
colSpan: 2,
59+
'redactor-attributes': { colSpan: 2, rowSpan: 2 }
60+
},
61+
children: []
62+
}
63+
64+
const tableHeadNode: Node = {
65+
type: NodeType.TABLE_HEAD,
66+
attrs: {
67+
rowSpan: 2,
68+
colSpan: 2,
69+
'redactor-attributes': { colSpan: 2, rowSpan: 2 }
70+
},
71+
children: []
72+
}
73+
5474
describe('Default node render options', () => {
5575
it('Should return document string', done => {
5676
const renderString = (defaultNodeOption[NodeType.DOCUMENT] as RenderNode)(node, next)
@@ -134,11 +154,11 @@ describe('Default node render options', () => {
134154
renderString = (defaultNodeOption[NodeType.TABLE_ROW] as RenderNode)(node, next)
135155
expect(renderString).toEqual('<tr>text</tr>')
136156

137-
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(node, next)
138-
expect(renderString).toEqual('<th>text</th>')
157+
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadNode, next)
158+
expect(renderString).toEqual('<th rowspan=\"2\" colspan=\"2\">text</th>')
139159

140-
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(node, next)
141-
expect(renderString).toEqual('<td>text</td>')
160+
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNode, next)
161+
expect(renderString).toEqual('<td rowspan=\"2\" colspan=\"2\">text</td>')
142162

143163
done()
144164
})

src/options/default-node-options.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,22 @@ export const defaultNodeOption: RenderOption = {
7575
return `<tr${node.attrs.style ? ` style="${node.attrs.style}"` : ``}${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}</tr>`
7676
},
7777
[NodeType.TABLE_HEAD]:(node: Node, next: Next) => {
78-
return `<th${node.attrs.style ? ` style="${node.attrs.style}"` : ``}${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}</th>`
78+
return `<th` +
79+
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
80+
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +
81+
`${node.attrs.style ? ` style="${node.attrs.style}"` : ``}`+
82+
`${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}`+
83+
`${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}` +
84+
`</th>`
7985
},
8086
[NodeType.TABLE_DATA]:(node: Node, next: Next) => {
81-
return `<td${node.attrs.style ? ` style="${node.attrs.style}"` : ``}${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}</td>`
87+
return `<td` +
88+
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
89+
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +
90+
`${node.attrs.style ? ` style="${node.attrs.style}"` : ``}`+
91+
`${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}`+
92+
`${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}` +
93+
`</td>`
8294
},
8395
[NodeType.BLOCK_QUOTE]:(node: Node, next: Next) => {
8496
return `<blockquote${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}${node.attrs.id ? ` id="${node.attrs.id}"` : ``}>${next(node.children)}</blockquote>`

0 commit comments

Comments
 (0)