Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/fromRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = {
const attrs: Record<string, string> = {}
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",
Expand Down
71 changes: 71 additions & 0 deletions test/expectedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,77 @@ export default {
"_version": 2
}
]
},
"RT-501":{
"html" : [
`<p><a href="google.in" target="_blank" title="google">ABC</a></p>`
],
"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"
}
]
}
]
}
]
}
]
}

}
9 changes: 9 additions & 0 deletions test/fromRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Comment thread
manojcon marked this conversation as resolved.
Outdated
})


Expand Down
11 changes: 11 additions & 0 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})

})

})

Loading