Skip to content

Commit 1282aff

Browse files
authored
Merge pull request #86 from contentstack/RT-501
Title attr added on A element
2 parents c1b28f1 + 98f33c4 commit 1282aff

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

src/fromRedactor.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = {
2020
const attrs: Record<string, string> = {}
2121
const target = el.getAttribute('target');
2222
const href = el.getAttribute('href');
23+
const title = el.getAttribute('title');
2324

2425
attrs.url = href ? href : '#';
2526

2627
if(target && target !== '') {
2728
attrs.target = target;
2829
}
30+
if(title && title !== '') {
31+
attrs.title = title;
32+
}
2933

3034
return {
3135
type: "a",

test/expectedJson.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,77 @@ export default {
24162416
"_version": 2
24172417
}
24182418
]
2419+
},
2420+
"RT-501":{
2421+
"html" : [
2422+
`<p><a href="google.in" target="_blank" title="google">ABC</a></p>`
2423+
],
2424+
"json" : [
2425+
{
2426+
"type": "doc",
2427+
"attrs": {},
2428+
"uid": "bd63f151aa8d402cae046c8dae440134",
2429+
"children": [
2430+
{
2431+
"type": "p",
2432+
"uid": "d2949ce0e0974ce783543edd37410c71",
2433+
"attrs": {},
2434+
"children": [
2435+
{
2436+
"uid": "7a2fd904668447ca8720428cbd2b0acc",
2437+
"type": "a",
2438+
"attrs": {
2439+
"url": "google.in",
2440+
"target": "_blank",
2441+
"title": "google"
2442+
},
2443+
"children": [
2444+
{
2445+
"text": "ABC"
2446+
}
2447+
]
2448+
}
2449+
]
2450+
}
2451+
],
2452+
}
2453+
],
2454+
"jsonWithRedactorAttributes": [
2455+
{
2456+
"type": "doc",
2457+
"attrs": {},
2458+
"uid": "bd63f151aa8d402cae046c8dae440134",
2459+
"children": [
2460+
{
2461+
"type": "p",
2462+
"uid": "d2949ce0e0974ce783543edd37410c71",
2463+
"attrs": {},
2464+
"children": [
2465+
{
2466+
"uid": "7a2fd904668447ca8720428cbd2b0acc",
2467+
"type": "a",
2468+
"attrs": {
2469+
"url": "google.in",
2470+
"target": "_blank",
2471+
"title": "google",
2472+
"style": {},
2473+
"redactor-attributes": {
2474+
"href": "google.in",
2475+
"target": "_blank",
2476+
"title": "google"
2477+
}
2478+
},
2479+
"children": [
2480+
{
2481+
"text": "ABC"
2482+
}
2483+
]
2484+
}
2485+
]
2486+
}
2487+
]
2488+
}
2489+
]
24192490
}
24202491

24212492
}

test/fromRedactor.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ describe("Testing html to json conversion", () => {
328328
expect(json).toStrictEqual({"type":"doc","uid":"uid","attrs":{},"children":[{"type":"p","attrs":{},"uid":"uid","children":[{"text":"Hello","attrs":{"style":{}},"bold":true},{"text":" Hii"}]}]})
329329

330330
})
331+
test("should add title attr to anchor tag", () => {
332+
const html = expectedValue["RT-501"].html[0];
333+
const json =expectedValue["RT-501"].jsonWithRedactorAttributes[0];
334+
335+
let jsonValue = htmlToJson(html)
336+
expect(omitdeep(jsonValue, "uid")).toStrictEqual(omitdeep(json, "uid"))
337+
})
331338
})
332339

333340

test/toRedactor.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,16 @@ describe("Testing json to html conversion", () => {
329329
})
330330
})
331331

332+
describe("RT-501",()=>{
333+
it("should add title attr to anchor tag",()=>{
334+
const html = expectedValue["RT-501"].html[0];
335+
const json =expectedValue["RT-501"].json[0];
336+
337+
let htmlValue = toRedactor(json)
338+
expect(htmlValue).toBe(html);
339+
})
340+
341+
})
342+
332343
})
333344

0 commit comments

Comments
 (0)