Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog

## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.5) (2024-05-31)
## [1.3.6](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.6) (2024-05-31)
- Fix: handle case of td or th nodes with attr void:true

## [1.3.5](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.5) (2024-05-31)
- Feat: updateAssetURLForGQL added
- Fix: add rowspan and colspan attribute to td and th nodes

## [1.3.4](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.4) (2024-05-13)
- Fixes for vulnerability issues related to regular expression and options
Expand Down
18 changes: 18 additions & 0 deletions __test__/default-node-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ const tableHeadNode: Node = {
children: []
}

const tableDataNodeWithVoid: Node = {
type: NodeType.TABLE_DATA,
attrs: { void: true },
children: []
}

const tableHeadNodeWithVoid: Node = {
type: NodeType.TABLE_HEAD,
attrs: { void: true },
children: []
}

describe('Default node render options', () => {
it('Should return document string', done => {
const renderString = (defaultNodeOption[NodeType.DOCUMENT] as RenderNode)(node, next)
Expand Down Expand Up @@ -160,6 +172,12 @@ describe('Default node render options', () => {
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNode, next)
expect(renderString).toEqual('<td rowspan=\"2\" colspan=\"2\">text</td>')

renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadNodeWithVoid, next)
expect(renderString).toEqual('')

renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNodeWithVoid, next)
expect(renderString).toEqual('')

done()
})
it('Should return block quote string', done => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/utils",
"version": "1.3.5",
"version": "1.3.6",
"description": "Contentstack utilities for Javascript",
"main": "dist/index.es.js",
"types": "dist/types/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/options/default-node-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const defaultNodeOption: RenderOption = {
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>`
},
[NodeType.TABLE_HEAD]:(node: Node, next: Next) => {
if (node.attrs.void) return '';

return `<th` +
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +
Expand All @@ -84,6 +86,8 @@ export const defaultNodeOption: RenderOption = {
`</th>`
},
[NodeType.TABLE_DATA]:(node: Node, next: Next) => {
if (node.attrs.void) return '';

return `<td` +
`${node.attrs.rowSpan ? ` rowspan="${node.attrs.rowSpan}"` : ``}` +
`${node.attrs.colSpan ? ` colspan="${node.attrs.colSpan}"` : ``}` +
Expand Down