Skip to content

Commit f9a891a

Browse files
authored
Merge pull request #72 from contentstack/next
Fix: Empty string in case td or th node had void:true
2 parents 44eb60a + 7e5f54d commit f9a891a

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22

3-
## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.5) (2024-05-31)
3+
## [1.3.6](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.6) (2024-05-31)
4+
- Fix: handle case of td or th nodes with attr void:true
5+
6+
## [1.3.5](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.5) (2024-05-31)
47
- Feat: updateAssetURLForGQL added
8+
- Fix: add rowspan and colspan attribute to td and th nodes
59

610
## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.4) (2024-05-13)
711
- Fixes for vulnerability issues related to regular expression and options

__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 => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/utils",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "Contentstack utilities for Javascript",
55
"main": "dist/index.es.js",
66
"types": "dist/types/index.d.ts",

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)