Skip to content

Commit

Permalink
Merge pull request #49 from contentstack/development
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayesh2812 authored Jul 9, 2024
2 parents f0b242e + 31f2d08 commit 66df6d0
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 18 deletions.
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": "2.0.7",
"version": "2.0.8",
"description": "This Package converts Html Document to Json and vice-versa.",
"main": "lib/index.js",
"module": "lib/index.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
if (attrsJson['width']) {
let width = attrsJson['width']
if (width.slice(width.length - 1) === '%') {
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
} else {
style = `width: ${allattrs['width'] + '%'}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
} else {
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
}
} else {
if (allattrs['width']) {
Expand Down
109 changes: 100 additions & 9 deletions test/expectedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export default {
]
},
"6": {
"html": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\"/>",
"html": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://images.com/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\"/>",
"json": [
{
"type": "p",
Expand All @@ -542,7 +542,7 @@ export default {
{
"type": "reference",
"attrs": {
"asset-link": "https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
"asset-link": "https://images.com/captain_pardip.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
Expand All @@ -552,7 +552,7 @@ export default {
},
"redactor-attributes": {
"asset_uid": "blt5523ee02703e39f5",
"src": "https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
"src": "https://images.com/captain_pardip.jpg",
"width": "24.193548387096776",
"height": "auto",
"style": "width: 24.193548387096776; height: auto;"
Expand Down Expand Up @@ -595,15 +595,15 @@ export default {
{
"type": "reference",
"attrs": {
"asset-link": "https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
"asset-link": "https://images.com/logo_1.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
"type": "asset",
"style": {},
"redactor-attributes": {
"asset_uid": "blta2aad0332073026c",
"src": "https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
"src": "https://images.com/logo_1.jpg",
"height": "auto"
}
},
Expand All @@ -615,7 +615,7 @@ export default {
]
}
],
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776%; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://images.com/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
},
"7": {
"html": "<p>this is <a href=\"link.com\" target=\"_self\">link</a></p><p></p><div data-type='hr' style='border-top: 3px solid #bbb'></div><p></p><p class=\"className\">paragraph with class</p><p id=\"id\">paragraph with id</p>",
Expand Down Expand Up @@ -821,7 +821,7 @@ export default {
"htmlValue": "<p><span type=\"entry\" class=\"embedded-entry redactor-component inline-entry\" data-sys-entry-uid=\"blt4b49bbbcef428a61\" data-sys-entry-locale=\"en-us\" data-sys-content-type-uid=\"html_rte\" sys-style-type=\"inline\"></span> test</p>"
},
"11": {
"html": "<p></p><figure class=\"embedded-asset\" content-type-uid=\"sys_assets\" type=\"asset\" data-sys-asset-filelink=\"https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg\" data-sys-asset-uid=\"blt5523ee02703e39f5\" data-sys-asset-filename=\"test\" data-sys-asset-contenttype=\"image/jpeg\" sys-style-type=\"display\"></figure>",
"html": "<p></p><figure class=\"embedded-asset\" content-type-uid=\"sys_assets\" type=\"asset\" data-sys-asset-filelink=\"https://images.com/captain_pardip.jpg\" data-sys-asset-uid=\"blt5523ee02703e39f5\" data-sys-asset-filename=\"test\" data-sys-asset-contenttype=\"image/jpeg\" sys-style-type=\"display\"></figure>",
"json": [
{
"type": "p",
Expand All @@ -843,7 +843,7 @@ export default {
},
"type": "asset",
"target": "_self",
"asset-link": "https://***REMOVED***-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
"asset-link": "https://images.com/captain_pardip.jpg",
"asset-uid": "blt5523ee02703e39f5",
"display-type": "display",
"asset-name": "test",
Expand Down Expand Up @@ -1909,6 +1909,97 @@ export default {
}
]
}
},
"RT-154": {
"html": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://images.com/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776; height: auto;\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\"/>",
"json": [
{
"type": "p",
"attrs": {},
"uid": "67d60b59926c48b58cb6b5d899401c01",
"children": [
{
"text": ""
}
]
},
{
"type": "reference",
"attrs": {
"asset-link": "https://images.com/captain_pardip.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
"type": "asset",
"style": {
"height": "auto"
},
"redactor-attributes": {
"asset_uid": "blt5523ee02703e39f5",
"src": "https://images.com/captain_pardip.jpg",
"width": "24.193548387096776%",
"height": "auto",
"style": "width: 24.193548387096776; height: auto;"
},
"width": 24.193548387096776
},
"uid": "fe969de8727c4074a23442a71b57ebb8",
"children": [
{
"text": ""
}
]
},
{
"type": "p",
"attrs": {},
"uid": "8c912298ad0a4a458c189f12603c05fb",
"children": [
{
"text": ""
}
]
},
{
"type": "embed",
"attrs": {
"src": "https://www.***REMOVED***.com/embed/CSvFpBOe8eY",
"style": {},
"redactor-attributes": {
"src": "https://www.***REMOVED***.com/embed/CSvFpBOe8eY"
}
},
"uid": "26067652d613404b8091f6e83d7af301",
"children": [
{
"text": ""
}
]
},
{
"type": "reference",
"attrs": {
"asset-link": "https://images.com/logo_1.jpg",
"default": true,
"asset-type": "image/jpg",
"display-type": "display",
"type": "asset",
"style": {},
"redactor-attributes": {
"asset_uid": "blta2aad0332073026c",
"src": "https://images.com/logo_1.jpg",
"height": "auto"
}
},
"uid": "d56e691f59ce4d35934c6aa9325188a2",
"children": [
{
"text": ""
}
]
}
],
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://images.com/captain_pardip.jpg\" width=\"24.193548387096776\" height=\"auto\" style=\"width: 24.193548387096776%; height: auto;height: auto;\" type=\"asset\" sys-style-type=\"download\"/><p></p><iframe src=\"https://www.***REMOVED***.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
}

}
10 changes: 4 additions & 6 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ describe("Testing json to html conversion", () => {
let testResult = isEqual(htmlValue, expectedValue['5'].html)
expect(testResult).toBe(true)
})
it("Image and iframe conversion", () => {
let jsonValue = expectedValue["6"].json

let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
let testResult = isEqual(htmlValue, expectedValue['6'].htmlUpdated)
expect(testResult).toBe(true)
it.each(["6", "RT-154"])("Image and iframe conversion", (index) => {
let jsonValue = expectedValue[index].json
let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
expect(htmlValue).toBe(expectedValue[index].htmlUpdated)
})
it("Link ,divider and property conversion", () => {
let jsonValue = expectedValue["7"].json
Expand Down

0 comments on commit 66df6d0

Please sign in to comment.