diff --git a/src/fromRedactor.tsx b/src/fromRedactor.tsx index 525f27a..da4ef56 100644 --- a/src/fromRedactor.tsx +++ b/src/fromRedactor.tsx @@ -121,6 +121,7 @@ const TEXT_TAGS: IHtmlToJsonTextTags = { I: () => ({ italic: true }), S: () => ({ strikethrough: true }), STRONG: () => ({ bold: true }), + B: () => ({ bold: true }), U: () => ({ underline: true }), SUP: () => ({ superscript: true }), SUB: () => ({ subscript: true }) @@ -863,7 +864,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject } let noOfInlineElement = 0 Array.from(el.parentNode?.childNodes || []).forEach((child: any) => { - if (child.nodeType === 3 || child.nodeName === 'SPAN' || child.nodeName === 'A' || (options?.allowNonStandardTags && child.getAttribute('inline'))) { + if (child.nodeType === 3 || child.nodeName === 'SPAN' || child.nodeName === 'A' || (options?.allowNonStandardTags && child.getAttribute('inline')) || child.nodeName in TEXT_TAGS) { noOfInlineElement += 1 } }) @@ -1084,4 +1085,4 @@ function getTbodyChildren (rows: any[]) { }, []) return newTbodyChildren -} \ No newline at end of file +} diff --git a/test/fromRedactor.test.ts b/test/fromRedactor.test.ts index e27debd..f84adb7 100644 --- a/test/fromRedactor.test.ts +++ b/test/fromRedactor.test.ts @@ -315,6 +315,19 @@ describe("Testing html to json conversion", () => { const json = htmlToJson(html) expect(json).toEqual({ type: "doc", attrs: {}, uid: "uid", children:[{ type: "social-embeds", uid: 'uid', attrs: { src: "https://www.youtube.com/embed/3V-Sq7_uHXQ" }, children: [{ text: ""}] }]}) }) + + test("should replace all instances of and proper json marks", () => { + const html = `
HelloTest2World
` + const json = htmlToJson(html) + expect(json).toStrictEqual({"type":"doc","uid":"uid","attrs":{},"children":[{"type":"p","attrs":{},"uid":"uid","children":[{"text":"Hello","attrs":{"style":{}},"bold":true},{"text":"Test2","attrs":{"style":{}},"italic":true},{"text":"World","attrs":{"style":{}},"bold":true}]}]}) + }) + + test("should not add fragment for html containing a text tag and span tag", () => { + const html = `Hello Hii
` + const json = htmlToJson(html) + expect(json).toStrictEqual({"type":"doc","uid":"uid","attrs":{},"children":[{"type":"p","attrs":{},"uid":"uid","children":[{"text":"Hello","attrs":{"style":{}},"bold":true},{"text":" Hii"}]}]}) + + }) })