Skip to content

Commit ae88512

Browse files
committed
fix: remove invisible psace added in json text in case of nbsp
1 parent 281e231 commit ae88512

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/fromRedactor.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
206206
if (el.textContent === '\n') {
207207
return null
208208
}
209+
if (options?.addNbspForEmptyBlocks && el.textContent.trim() === '') {
210+
return { text: '' }
211+
}
209212
if (el.parentNode.nodeName === 'SPAN') {
210213
let attrs = { style: {} }
211214
const metadata = {}
@@ -297,6 +300,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
297300
let children: any = flatten(Array.from(parent.childNodes).map((child) => fromRedactor(child, options)))
298301
children = children.filter((child: any) => child !== null)
299302
children = traverseChildAndWarpChild(children, options?.allowNonStandardTags)
303+
300304
if (children.length === 0) {
301305
children = [{ text: '' }]
302306
}

0 commit comments

Comments
 (0)