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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
if (jsonValue.hasOwnProperty('text')) {
let text = jsonValue['text'].replace(/</g, '&lt;').replace(/>/g, '&gt;')
if (jsonValue['break']) {
text += `<br/>`
text = text.replace(/\n/g, '<br/>')
}
if(jsonValue['classname'] || jsonValue['id']){
if(jsonValue['classname'] && jsonValue['id']){
Expand Down
73 changes: 71 additions & 2 deletions test/expectedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<ul><li dir="ltr">Vehicle
<br/>This is test</li></ul>`,
html: `<ul><li dir="ltr">Vehicle<br/>This is test</li></ul>`,
expectedJson: {
"uid": "uid",
"type": "doc",
Expand Down Expand Up @@ -2347,6 +2346,76 @@ export default {
"_version": 2
}
]
},
"RT-483":{
"html" : [
`<p dir="ltr">HI<br/><br/>Hi shift enter x2</p>`,
`<p dir="ltr"><br/>HI<br/><br/>Hi <br/> shift enter x2</p>`
],
"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
}
]
}

}
13 changes: 13 additions & 0 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
})
})

})

Loading