Skip to content

Commit ee07e90

Browse files
Merge pull request #90 from contentstack/RT-531
2 parents 302fad6 + f12235e commit ee07e90

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
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": "3.0.2",
3+
"version": "3.0.3",
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ELEMENT_TYPES: IJsonToHtmlElementTags = {
6060
return `<ul${attrs}>${child}</ul>`
6161
},
6262
code: (attrs: any, child: any) => {
63-
return `<pre${attrs}>${child}</pre>`
63+
return `<pre${attrs}>${child.replace(/<br\/?>/g, '\n')}</pre>`
6464
},
6565
li: (attrs: any, child: any) => {
6666
return `<li${attrs}>${child}</li>`
@@ -602,7 +602,6 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
602602
figureStyles
603603
)
604604
}
605-
606605
return children
607606
}
608607

test/toRedactor.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,8 @@ test("should add nbsp for empty blocks", () => {
348348
expect(html).toBe(`<p>Hi</p><p>&nbsp;</p><p>&nbsp;</p><p>Hello</p>`);
349349
});
350350

351+
test("should convert codeblock to proper html, where \n should not be replaced with <br/>",()=>{
352+
const json = {"type":"doc","uid":"uid","attrs":{},"children":[{"type":"code","attrs":{},"uid":"uid","children":[{"text":"Hi\nHello"}]}]};
353+
const html = toRedactor(json);
354+
expect(html).toBe(`<pre>Hi\nHello</pre>`);
355+
})

0 commit comments

Comments
 (0)