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.2",
"version": "3.0.3",
"description": "This Package converts Html Document to Json and vice-versa.",
"main": "lib/index.js",
"module": "lib/index.mjs",
Expand Down
3 changes: 1 addition & 2 deletions src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ELEMENT_TYPES: IJsonToHtmlElementTags = {
return `<ul${attrs}>${child}</ul>`
},
code: (attrs: any, child: any) => {
return `<pre${attrs}>${child}</pre>`
return `<pre${attrs}>${child.replace(/<br\/?>/g, '\n')}</pre>`
},
li: (attrs: any, child: any) => {
return `<li${attrs}>${child}</li>`
Expand Down Expand Up @@ -602,7 +602,6 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
figureStyles
)
}

return children
}

Expand Down
5 changes: 5 additions & 0 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,8 @@ test("should add nbsp for empty blocks", () => {
expect(html).toBe(`<p>Hi</p><p>&nbsp;</p><p>&nbsp;</p><p>Hello</p>`);
});

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