diff --git a/package.json b/package.json index baf7955..e353a44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/json-rte-serializer", - "version": "3.0.0", + "version": "3.0.1", "description": "This Package converts Html Document to Json and vice-versa.", "main": "lib/index.js", "module": "lib/index.mjs", diff --git a/src/toRedactor.tsx b/src/toRedactor.tsx index 57f7b98..0cdfc24 100644 --- a/src/toRedactor.tsx +++ b/src/toRedactor.tsx @@ -234,7 +234,7 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string if (jsonValue.hasOwnProperty('text')) { let text = jsonValue['text'].replace(//g, '>') if (jsonValue['break']) { - text += `
` + text = text.replace(/\n/g, '
') } if(jsonValue['classname'] || jsonValue['id']){ if(jsonValue['classname'] && jsonValue['id']){ diff --git a/test/expectedJson.ts b/test/expectedJson.ts index bed8a98..57f2a8a 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -1870,8 +1870,7 @@ export default { expectedJson: {"type":"doc","uid":"uid","attrs":{},"children":[{"type":"table","attrs":{"style":{},"redactor-attributes":{"border":"1"},"rows":5,"cols":4,"colWidths":[250,250,250,250],"disabledCols":[1,2,3]},"uid":"uid","children":[{"type":"thead","attrs":{},"uid":"uid","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"th","attrs":{},"uid":"uid","children":[{"text":"Header 1"}]},{"type":"th","attrs":{"colSpan":3,"style":{},"redactor-attributes":{"colspan":"3"}},"uid":"uid","children":[{"text":"Header 2"}]},{"type":"th","attrs":{"void":true},"children":[{"text":""}]},{"type":"th","attrs":{"void":true},"children":[{"text":""}]},{"type":"th","attrs":{},"uid":"uid","children":[{"text":"Header 3"}]}]}]},{"type":"tbody","attrs":{},"uid":"uid","children":[{"type":"trgrp","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{"rowSpan":2,"style":{},"redactor-attributes":{"rowspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 1"}]},{"type":"td","attrs":{"colSpan":2,"style":{},"redactor-attributes":{"colspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 2"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 1, Col 3"}]},{"type":"td","attrs":{"rowSpan":2,"style":{},"redactor-attributes":{"rowspan":"2"}},"uid":"uid","children":[{"text":"Row 1, Col 4"}]}]},{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 2"}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 3"}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 2, Col 4"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]}]}]},{"type":"trgrp","children":[{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 3, Col 1"}]},{"type":"td","attrs":{"rowSpan":2,"colSpan":3,"style":{},"redactor-attributes":{"colspan":"3","rowspan":"2"}},"uid":"uid","children":[{"text":"Row 3, Col 2"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 3, Col 5"}]}]},{"type":"tr","attrs":{},"uid":"uid","children":[{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 4, Col 1"}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{"void":true},"children":[{"text":""}]},{"type":"td","attrs":{},"uid":"uid","children":[{"text":"Row 4, Col 5"}]}]}]}]}]}]} }, 'fix_EB-745' : { - html: ``, + html: ``, expectedJson: { "uid": "uid", "type": "doc", @@ -2347,6 +2346,76 @@ export default { "_version": 2 } ] + }, + "RT-483":{ + "html" : [ + `

HI

Hi shift enter x2

`, + `


HI

Hi
shift enter x2

` + ], + "json" : [ + { + "uid": "a59f9108e99747d4b3358d9e22b7c685", + "type": "doc", + "attrs": { + "dirty": true + }, + "children": [ + { + "type": "p", + "uid": "bedef68ac71c4f41bdee935e78fb7c31", + "attrs": { + "style": {}, + "redactor-attributes": {}, + "dir": "ltr" + }, + "children": [ + { + "text": "HI" + }, + { + "text": "\n\n", + "break": true + }, + { + "text": "Hi shift enter x2" + } + ] + } + ], + "_version": 2 + }, + { + "uid": "a59f9108e99747d4b3358d9e22b7c685", + "type": "doc", + "attrs": { + "dirty": true + }, + "children": [ + { + "type": "p", + "uid": "bedef68ac71c4f41bdee935e78fb7c31", + "attrs": { + "style": {}, + "redactor-attributes": {}, + "dir": "ltr" + }, + "children": [ + { + "text": "\nHI" + }, + { + "text": "\n\n", + "break": true + }, + { + "text": "Hi \n shift enter x2" + } + ] + } + ], + "_version": 2 + } + ] } } \ No newline at end of file diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index 86a5203..c1a10ae 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -316,5 +316,18 @@ describe("Testing json to html conversion", () => { }) + describe("RT-483",()=>{ + it("should enter br tags equivalent to no.of times 'shift+enter' is pressed",()=>{ + const json = expectedValue['RT-483'].json[0]; + const html = toRedactor(json); + expect(html).toBe(expectedValue['RT-483'].html[0]); + }) + it("should replace /n withing other texts to br tags",()=>{ + const json = expectedValue['RT-483'].json[1]; + const html = toRedactor(json); + expect(html).toBe(expectedValue['RT-483'].html[1]); + }) + }) + })