Skip to content

Commit 950c02d

Browse files
committed
fix: ♻️ ignore td/th in case attrs had void:true
1 parent 8ad0330 commit 950c02d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

__test__/default-node-options.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ const tableHeadNode: Node = {
7171
children: []
7272
}
7373

74+
const tableDataNodeWithVoid: Node = {
75+
type: NodeType.TABLE_DATA,
76+
attrs: { void: true },
77+
children: []
78+
}
79+
80+
const tableHeadNodeWithVoid: Node = {
81+
type: NodeType.TABLE_HEAD,
82+
attrs: { void: true },
83+
children: []
84+
}
85+
7486
describe('Default node render options', () => {
7587
it('Should return document string', done => {
7688
const renderString = (defaultNodeOption[NodeType.DOCUMENT] as RenderNode)(node, next)
@@ -160,6 +172,12 @@ describe('Default node render options', () => {
160172
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNode, next)
161173
expect(renderString).toEqual('<td rowspan=\"2\" colspan=\"2\">text</td>')
162174

175+
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadNodeWithVoid, next)
176+
expect(renderString).toEqual('')
177+
178+
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNodeWithVoid, next)
179+
expect(renderString).toEqual('')
180+
163181
done()
164182
})
165183
it('Should return block quote string', done => {

src/options/default-node-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ 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+
if (node.attrs.void) return '';
79+
7880
return `<th` +
7981
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
8082
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +
@@ -84,6 +86,8 @@ export const defaultNodeOption: RenderOption = {
8486
`</th>`
8587
},
8688
[NodeType.TABLE_DATA]:(node: Node, next: Next) => {
89+
if (node.attrs.void) return '';
90+
8791
return `<td` +
8892
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
8993
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +

0 commit comments

Comments
 (0)