From 8cda1833bc048065ed017cffdb6ca04694ae9b0e Mon Sep 17 00:00:00 2001 From: Shreya Kamble Date: Thu, 12 Jun 2025 15:59:19 +0530 Subject: [PATCH 1/2] fix: rt-531 --- src/toRedactor.tsx | 3 +-- test/toRedactor.test.ts | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) 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
`); +}) From f12235e238a94708828e3efb883ee36d1165dfa1 Mon Sep 17 00:00:00 2001 From: shreya-kamble <92981124+shreya-kamble@users.noreply.github.com> Date: Thu, 12 Jun 2025 16:03:32 +0530 Subject: [PATCH 2/2] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",