Skip to content

Commit 7fce654

Browse files
fix: serializer not handling "\n" and converting it to </br>
1 parent e136e5d commit 7fce654

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/fromRedactor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
183183
} else if (el.nodeType !== 1) {
184184
return null
185185
} else if (el.nodeName === 'BR') {
186-
return { text: ' ', break: true, separaterId: generateId() }
186+
return { text: '\n', break: false, separaterId: generateId() }
187187
} else if (el.nodeName === 'META') {
188188
return null
189189
} else if (el.nodeName === 'COLGROUP') {

src/toRedactor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
165165
if (jsonValue['break']) {
166166
text += `<br/>`
167167
}
168+
if (jsonValue.text.includes('\n')) {
169+
text = text.replace(/\n/g, '<br/>')
170+
}
168171
Object.entries(jsonValue).forEach(([key, value]) => {
169172
if(TEXT_WRAPPERS.hasOwnProperty(key)){
170173
text = TEXT_WRAPPERS[key](text,value)

0 commit comments

Comments
 (0)