From 950c02d3dc2f56993eadf72ed4f71d98f6150ebe Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 31 May 2024 15:32:50 +0530 Subject: [PATCH 1/2] fix: :recycle: ignore td/th in case attrs had void:true --- __test__/default-node-options.test.ts | 18 ++++++++++++++++++ src/options/default-node-options.ts | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/__test__/default-node-options.test.ts b/__test__/default-node-options.test.ts index 618be74..986c1d2 100644 --- a/__test__/default-node-options.test.ts +++ b/__test__/default-node-options.test.ts @@ -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) @@ -160,6 +172,12 @@ describe('Default node render options', () => { renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNode, next) expect(renderString).toEqual('text') + 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 => { diff --git a/src/options/default-node-options.ts b/src/options/default-node-options.ts index e5cc8d8..2d18c2a 100644 --- a/src/options/default-node-options.ts +++ b/src/options/default-node-options.ts @@ -75,6 +75,8 @@ export const defaultNodeOption: RenderOption = { return `${next(node.children)}` }, [NodeType.TABLE_HEAD]:(node: Node, next: Next) => { + if (node.attrs.void) return ''; + return `` }, [NodeType.TABLE_DATA]:(node: Node, next: Next) => { + if (node.attrs.void) return ''; + return ` Date: Fri, 31 May 2024 15:37:13 +0530 Subject: [PATCH 2/2] chore: add changelog and update version --- CHANGELOG.md | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf15aa..073f914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index 210540b..97d3c75 100644 --- a/package.json +++ b/package.json @@ -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",