diff --git a/package.json b/package.json index 2314fe5..46f84fd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/toRedactor.tsx b/src/toRedactor.tsx index 4d39395..02ab067 100644 --- a/src/toRedactor.tsx +++ b/src/toRedactor.tsx @@ -60,7 +60,7 @@ const ELEMENT_TYPES: IJsonToHtmlElementTags = { return `${child}` }, code: (attrs: any, child: any) => { - return `${child}` + return `${child.replace(//g, '\n')}` }, li: (attrs: any, child: any) => { return `${child}` @@ -602,7 +602,6 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string figureStyles ) } - return children } diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index 854a6db..97997c7 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -348,3 +348,8 @@ test("should add nbsp for empty blocks", () => { expect(html).toBe(`

Hi

 

 

Hello

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