From 02d291f4f5581d24830591e9edc2bfea0f98d3aa Mon Sep 17 00:00:00 2001 From: Ashwini-Rathod Date: Thu, 9 Mar 2023 17:47:16 +0530 Subject: [PATCH 1/4] fix: fix for adding inline classname and id while html conversion --- src/toRedactor.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/toRedactor.tsx b/src/toRedactor.tsx index 05a56bf..b0fb9ea 100644 --- a/src/toRedactor.tsx +++ b/src/toRedactor.tsx @@ -153,7 +153,7 @@ const TEXT_WRAPPERS: IJsonToHtmlTextTags = { }, 'inlineCode': (child: any, value:any) => { return `${child}` - } + }, } export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string => { //TODO: optimize assign once per function call @@ -165,6 +165,17 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string if (jsonValue['break']) { text += `
` } + if(jsonValue['classname'] || jsonValue['id']){ + if(jsonValue['classname'] && jsonValue['id']){ + text = `${text}` + } + else if(jsonValue['classname'] && !jsonValue['id']){ + text = `${text}` + } + else if(jsonValue['id'] && !jsonValue['classname']){ + text = `${text}` + } + } if (jsonValue.text.includes('\n')) { text = text.replace(/\n/g, '
') } From 0e7243d2fbd1f567964021bc08ddb39c2a68a4ec Mon Sep 17 00:00:00 2001 From: Ashwini-Rathod Date: Mon, 13 Mar 2023 13:01:24 +0530 Subject: [PATCH 2/4] chore: changed class-name to class --- src/toRedactor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/toRedactor.tsx b/src/toRedactor.tsx index b0fb9ea..d937b42 100644 --- a/src/toRedactor.tsx +++ b/src/toRedactor.tsx @@ -167,10 +167,10 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string } if(jsonValue['classname'] || jsonValue['id']){ if(jsonValue['classname'] && jsonValue['id']){ - text = `${text}` + text = `${text}` } else if(jsonValue['classname'] && !jsonValue['id']){ - text = `${text}` + text = `${text}` } else if(jsonValue['id'] && !jsonValue['classname']){ text = `${text}` From 24138051ab10cfb6f6f768b871c89876d089563a Mon Sep 17 00:00:00 2001 From: Ashwini-Rathod Date: Mon, 13 Mar 2023 15:15:15 +0530 Subject: [PATCH 3/4] test: added test for inline class and id --- test/expectedJson.ts | 31 +++++++++++++++++++++++++++++++ test/toRedactor.test.ts | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/test/expectedJson.ts b/test/expectedJson.ts index 807af57..2ef1af5 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -1714,5 +1714,36 @@ export default { ] } ] + }, + "inline-classname-and-id": { + "html": '

This is test for adding inline class and id

', + "json": [ + { + "type": "p", + "attrs": {}, + "children": [ + { + "type": "span", + "attrs": {}, + "children": [ + { + "text": "This is test for adding inline " + }, + { + "text": "class", + "classname": "class" + }, + { + "text": " and " + }, + { + "text": "id", + "id": "id" + } + ] + } + ] + } + ] } } \ No newline at end of file diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index 566318f..f7564a5 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -115,4 +115,11 @@ describe("Testing json to html conversion", () => { let testResult = isEqual(htmlValue, expectedValue["'\n' to
"].html) expect(testResult).toBe(true) }) + + it("Inline classname and id", () => { + let jsonValue = expectedValue["inline-classname-and-id"].json + let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue }) + let testResult = isEqual(htmlValue, expectedValue["inline-classname-and-id"].html) + expect(testResult).toBe(true) + }) }) \ No newline at end of file From 7444ad27a7679fe89bb7b501432b850b341a91c7 Mon Sep 17 00:00:00 2001 From: Ashwini-Rathod Date: Thu, 16 Mar 2023 16:10:59 +0530 Subject: [PATCH 4/4] updated version in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 531ceea..216768a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/json-rte-serializer", - "version": "2.0.1", + "version": "2.0.2", "description": "This Package converts Html Document to Json and vice-versa.", "main": "lib/index.js", "types": "lib/index.d.ts",