From b8f20a50e6921b6fab41c7a96056ef7d9a85b10e Mon Sep 17 00:00:00 2001 From: "manoj.muduli" Date: Tue, 13 May 2025 18:06:08 +0530 Subject: [PATCH 1/2] Titel attr added on A element --- src/fromRedactor.tsx | 4 +++ test/expectedJson.ts | 71 +++++++++++++++++++++++++++++++++++++++ test/fromRedactor.test.ts | 9 +++++ test/toRedactor.test.ts | 11 ++++++ 4 files changed, 95 insertions(+) diff --git a/src/fromRedactor.tsx b/src/fromRedactor.tsx index da4ef56..e33f9e0 100644 --- a/src/fromRedactor.tsx +++ b/src/fromRedactor.tsx @@ -20,12 +20,16 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = { const attrs: Record = {} const target = el.getAttribute('target'); const href = el.getAttribute('href'); + const title = el.getAttribute('title'); attrs.url = href ? href : '#'; if(target && target !== '') { attrs.target = target; } + if(title && title !== '') { + attrs.title = title; + } return { type: "a", diff --git a/test/expectedJson.ts b/test/expectedJson.ts index 57f2a8a..796a240 100644 --- a/test/expectedJson.ts +++ b/test/expectedJson.ts @@ -2416,6 +2416,77 @@ export default { "_version": 2 } ] + }, + "RT-501":{ + "html" : [ + `

ABC

` + ], + "json" : [ + { + "type": "doc", + "attrs": {}, + "uid": "bd63f151aa8d402cae046c8dae440134", + "children": [ + { + "type": "p", + "uid": "d2949ce0e0974ce783543edd37410c71", + "attrs": {}, + "children": [ + { + "uid": "7a2fd904668447ca8720428cbd2b0acc", + "type": "a", + "attrs": { + "url": "google.in", + "target": "_blank", + "title": "google" + }, + "children": [ + { + "text": "ABC" + } + ] + } + ] + } + ], + } + ], + "jsonWithRedactorAttributes": [ + { + "type": "doc", + "attrs": {}, + "uid": "bd63f151aa8d402cae046c8dae440134", + "children": [ + { + "type": "p", + "uid": "d2949ce0e0974ce783543edd37410c71", + "attrs": {}, + "children": [ + { + "uid": "7a2fd904668447ca8720428cbd2b0acc", + "type": "a", + "attrs": { + "url": "google.in", + "target": "_blank", + "title": "google", + "style": {}, + "redactor-attributes": { + "href": "google.in", + "target": "_blank", + "title": "google" + } + }, + "children": [ + { + "text": "ABC" + } + ] + } + ] + } + ] + } + ] } } \ No newline at end of file diff --git a/test/fromRedactor.test.ts b/test/fromRedactor.test.ts index 5c1fa63..878e102 100644 --- a/test/fromRedactor.test.ts +++ b/test/fromRedactor.test.ts @@ -328,6 +328,15 @@ describe("Testing html to json conversion", () => { expect(json).toStrictEqual({"type":"doc","uid":"uid","attrs":{},"children":[{"type":"p","attrs":{},"uid":"uid","children":[{"text":"Hello","attrs":{"style":{}},"bold":true},{"text":" Hii"}]}]}) }) + test("should add title attr to anchor tag", () => { + const html = expectedValue["RT-501"].html[0]; + const json =expectedValue["RT-501"].jsonWithRedactorAttributes[0]; + + let jsonValue = htmlToJson(html) + let testResult = isEqual(omitdeep(jsonValue, "uid"), omitdeep(json, "uid")) + + expect(testResult).toBe(true) + }) }) diff --git a/test/toRedactor.test.ts b/test/toRedactor.test.ts index c1a10ae..3054e13 100644 --- a/test/toRedactor.test.ts +++ b/test/toRedactor.test.ts @@ -329,5 +329,16 @@ describe("Testing json to html conversion", () => { }) }) + describe("RT-501",()=>{ + it("should add title attr to anchor tag",()=>{ + const html = expectedValue["RT-501"].html[0]; + const json =expectedValue["RT-501"].json[0]; + + let htmlValue = toRedactor(json) + expect(htmlValue).toBe(html); + }) + + }) + }) From 98f33c4fd4d86c08cbb100fb7ae429ae467b529a Mon Sep 17 00:00:00 2001 From: "manoj.muduli" Date: Tue, 13 May 2025 18:24:45 +0530 Subject: [PATCH 2/2] resolve PR comment --- test/fromRedactor.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/fromRedactor.test.ts b/test/fromRedactor.test.ts index 878e102..a145ad7 100644 --- a/test/fromRedactor.test.ts +++ b/test/fromRedactor.test.ts @@ -333,9 +333,7 @@ describe("Testing html to json conversion", () => { const json =expectedValue["RT-501"].jsonWithRedactorAttributes[0]; let jsonValue = htmlToJson(html) - let testResult = isEqual(omitdeep(jsonValue, "uid"), omitdeep(json, "uid")) - - expect(testResult).toBe(true) + expect(omitdeep(jsonValue, "uid")).toStrictEqual(omitdeep(json, "uid")) }) })