Skip to content

Commit 8cda183

Browse files
committed
fix: rt-531
1 parent 302fad6 commit 8cda183

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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)