Skip to content

Commit 591464f

Browse files
authored
Merge pull request #68 from contentstack/RT-383
Rt 383
2 parents 3609671 + 6bf6474 commit 591464f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/toRedactor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
379379
}
380380
if (attrsJson['width']) {
381381
let width = attrsJson['width']
382+
if(typeof width === 'number'){
383+
width = width.toString()
384+
}
382385
if (width.slice(width.length - 1) === '%') {
383386
style = `width: ${allattrs['width'] + '%'}; height: ${attrsJson['height'] ? attrsJson['height'] : 'auto'};`
384387
} else {

test/toRedactor.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,11 @@ describe("Testing json to html conversion", () => {
268268
expect(html).toBe(expectedValue["RT-360"].html[2]);
269269
})
270270
})
271+
272+
test('should convert numeric width to string', () => {
273+
const json = {"type":"doc","uid":"0ebe9a3b835d413595885c44d9527b72","attrs":{},"children":[{"type":"img","attrs":{"style":{"text-align":"center"},"redactor-attributes":{"alt":"Infographic showing 3 results from Forrester study of Contentstack CMS: $3M increase in profit, $507.3K productivity savings and $2.0M savings due to reduced time to publish.","src":"https://images.contentstack.io/v3/assets/blt7359e2a55efae483/bltea2a11144a2c68b5/63c08b7f438f80612c397994/CS_Infographics_ForresterReport_Data_3_1200x628_(1).png","position":"center","width":641},"url":"https://images.contentstack.io/v3/assets/blt7359e2a55efae483/bltea2a11144a2c68b5/63c08b7f438f80612c397994/CS_Infographics_ForresterReport_Data_3_1200x628_(1).png","width":641},"uid":"15516d511e7a4e28b418e49bdba0464d","children":[{"text":""}]}] }
274+
const html = toRedactor(json);
275+
expect(html).toBe(`<img alt="Infographic showing 3 results from Forrester study of Contentstack CMS: $3M increase in profit, $507.3K productivity savings and $2.0M savings due to reduced time to publish." src="https://images.contentstack.io/v3/assets/blt7359e2a55efae483/bltea2a11144a2c68b5/63c08b7f438f80612c397994/CS_Infographics_ForresterReport_Data_3_1200x628_(1).png" position="center" width="641" style="width: 641; height: auto;" />`)
276+
})
271277
})
272278

0 commit comments

Comments
 (0)