Skip to content

Commit 48a8edd

Browse files
authored
Merge pull request #49 from contentstack/development
2 parents 366d679 + 50b58d9 commit 48a8edd

File tree

4 files changed

+107
-18
lines changed

4 files changed

+107
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/json-rte-serializer",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"description": "This Package converts Html Document to Json and vice-versa.",
55
"main": "lib/index.js",
66
"module": "lib/index.mjs",

src/toRedactor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
375375
if (attrsJson['width']) {
376376
let width = attrsJson['width']
377377
if (width.slice(width.length - 1) === '%') {
378-
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
379-
} else {
380378
style = `width: ${allattrs['width'] + '%'}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
379+
} else {
380+
style = `width: ${allattrs['width']}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
381381
}
382382
} else {
383383
if (allattrs['width']) {

test/expectedJson.ts

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ export default {
527527
]
528528
},
529529
"6": {
530-
"html": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\"/>",
530+
"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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\"/>",
531531
"json": [
532532
{
533533
"type": "p",
@@ -542,7 +542,7 @@ export default {
542542
{
543543
"type": "reference",
544544
"attrs": {
545-
"asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
545+
"asset-link": "https://images.com/captain_pardip.jpg",
546546
"default": true,
547547
"asset-type": "image/jpg",
548548
"display-type": "display",
@@ -552,7 +552,7 @@ export default {
552552
},
553553
"redactor-attributes": {
554554
"asset_uid": "blt5523ee02703e39f5",
555-
"src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
555+
"src": "https://images.com/captain_pardip.jpg",
556556
"width": "24.193548387096776",
557557
"height": "auto",
558558
"style": "width: 24.193548387096776; height: auto;"
@@ -595,15 +595,15 @@ export default {
595595
{
596596
"type": "reference",
597597
"attrs": {
598-
"asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
598+
"asset-link": "https://images.com/logo_1.jpg",
599599
"default": true,
600600
"asset-type": "image/jpg",
601601
"display-type": "display",
602602
"type": "asset",
603603
"style": {},
604604
"redactor-attributes": {
605605
"asset_uid": "blta2aad0332073026c",
606-
"src": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg",
606+
"src": "https://images.com/logo_1.jpg",
607607
"height": "auto"
608608
}
609609
},
@@ -615,7 +615,7 @@ export default {
615615
]
616616
}
617617
],
618-
"htmlUpdated": "<p></p><img asset_uid=\"blt5523ee02703e39f5\" src=\"https://dev16-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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blta2aad0332073026c/60dc3bf8214cd714eebe026b/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
618+
"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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
619619
},
620620
"7": {
621621
"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>",
@@ -821,7 +821,7 @@ export default {
821821
"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>"
822822
},
823823
"11": {
824-
"html": "<p></p><figure class=\"embedded-asset\" content-type-uid=\"sys_assets\" type=\"asset\" data-sys-asset-filelink=\"https://dev16-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>",
824+
"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>",
825825
"json": [
826826
{
827827
"type": "p",
@@ -843,7 +843,7 @@ export default {
843843
},
844844
"type": "asset",
845845
"target": "_self",
846-
"asset-link": "https://dev16-images.contentstack.com/v3/assets/blt8ffa7e7de8b20283/blt5523ee02703e39f5/60dc421ee5e22614ef8dadfa/captain_pardip.jpg",
846+
"asset-link": "https://images.com/captain_pardip.jpg",
847847
"asset-uid": "blt5523ee02703e39f5",
848848
"display-type": "display",
849849
"asset-name": "test",
@@ -1909,6 +1909,97 @@ export default {
19091909
}
19101910
]
19111911
}
1912+
},
1913+
"RT-154": {
1914+
"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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\"/>",
1915+
"json": [
1916+
{
1917+
"type": "p",
1918+
"attrs": {},
1919+
"uid": "67d60b59926c48b58cb6b5d899401c01",
1920+
"children": [
1921+
{
1922+
"text": ""
1923+
}
1924+
]
1925+
},
1926+
{
1927+
"type": "reference",
1928+
"attrs": {
1929+
"asset-link": "https://images.com/captain_pardip.jpg",
1930+
"default": true,
1931+
"asset-type": "image/jpg",
1932+
"display-type": "display",
1933+
"type": "asset",
1934+
"style": {
1935+
"height": "auto"
1936+
},
1937+
"redactor-attributes": {
1938+
"asset_uid": "blt5523ee02703e39f5",
1939+
"src": "https://images.com/captain_pardip.jpg",
1940+
"width": "24.193548387096776%",
1941+
"height": "auto",
1942+
"style": "width: 24.193548387096776; height: auto;"
1943+
},
1944+
"width": 24.193548387096776
1945+
},
1946+
"uid": "fe969de8727c4074a23442a71b57ebb8",
1947+
"children": [
1948+
{
1949+
"text": ""
1950+
}
1951+
]
1952+
},
1953+
{
1954+
"type": "p",
1955+
"attrs": {},
1956+
"uid": "8c912298ad0a4a458c189f12603c05fb",
1957+
"children": [
1958+
{
1959+
"text": ""
1960+
}
1961+
]
1962+
},
1963+
{
1964+
"type": "embed",
1965+
"attrs": {
1966+
"src": "https://www.youtube.com/embed/CSvFpBOe8eY",
1967+
"style": {},
1968+
"redactor-attributes": {
1969+
"src": "https://www.youtube.com/embed/CSvFpBOe8eY"
1970+
}
1971+
},
1972+
"uid": "26067652d613404b8091f6e83d7af301",
1973+
"children": [
1974+
{
1975+
"text": ""
1976+
}
1977+
]
1978+
},
1979+
{
1980+
"type": "reference",
1981+
"attrs": {
1982+
"asset-link": "https://images.com/logo_1.jpg",
1983+
"default": true,
1984+
"asset-type": "image/jpg",
1985+
"display-type": "display",
1986+
"type": "asset",
1987+
"style": {},
1988+
"redactor-attributes": {
1989+
"asset_uid": "blta2aad0332073026c",
1990+
"src": "https://images.com/logo_1.jpg",
1991+
"height": "auto"
1992+
}
1993+
},
1994+
"uid": "d56e691f59ce4d35934c6aa9325188a2",
1995+
"children": [
1996+
{
1997+
"text": ""
1998+
}
1999+
]
2000+
}
2001+
],
2002+
"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.youtube.com/embed/CSvFpBOe8eY\"></iframe><img asset_uid=\"blta2aad0332073026c\" src=\"https://images.com/logo_1.jpg\" height=\"auto\" type=\"asset\" sys-style-type=\"download\"/>"
19122003
}
1913-
2004+
19142005
}

test/toRedactor.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ describe("Testing json to html conversion", () => {
3333
let testResult = isEqual(htmlValue, expectedValue['5'].html)
3434
expect(testResult).toBe(true)
3535
})
36-
it("Image and iframe conversion", () => {
37-
let jsonValue = expectedValue["6"].json
38-
39-
let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
40-
let testResult = isEqual(htmlValue, expectedValue['6'].htmlUpdated)
41-
expect(testResult).toBe(true)
36+
it.each(["6", "RT-154"])("Image and iframe conversion", (index) => {
37+
let jsonValue = expectedValue[index].json
38+
let htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
39+
expect(htmlValue).toBe(expectedValue[index].htmlUpdated)
4240
})
4341
it("Link ,divider and property conversion", () => {
4442
let jsonValue = expectedValue["7"].json

0 commit comments

Comments
 (0)