Skip to content

Commit 35b62cf

Browse files
committed
image link and embed tag support for attribute url added
1 parent d0cf774 commit 35b62cf

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

__test__/json-to-html.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import {
1414
orderListJson,
1515
unorderListJson,
1616
imgJson,
17+
imgJsonURL,
1718
tableJson,
1819
blockquoteJson,
1920
codeJson,
20-
linkInPJson} from './mock/json-element-mock'
21+
linkInPJson,
22+
linkInPJsonUrl} from './mock/json-element-mock'
2123
import {
2224
blockquoteHtml,
2325
codeHtml,
@@ -350,7 +352,7 @@ describe('Node parse image content', () => {
350352
uid: 'entry_uid_19',
351353
supercharged_rte: [
352354
{
353-
...imgJson
355+
...imgJsonURL
354356
}
355357
],
356358
_embedded_items: {}
@@ -477,7 +479,7 @@ describe('Node parse link in paragraph content', () => {
477479
uid: 'entry_uid_19',
478480
supercharged_rte: [
479481
{
480-
...linkInPJson
482+
...linkInPJsonUrl
481483
},
482484
],
483485
_embedded_items: {}

__test__/mock/json-element-mock.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,32 @@ const imgJson = {
348348
type: "doc"
349349
}
350350

351+
const imgJsonURL = {
352+
uid: "06e34a7a4849d7fc2acd",
353+
_version: 13,
354+
attrs: {},
355+
children: [
356+
{
357+
"uid": "f3be74be3b64646e626",
358+
"type": "img",
359+
"attrs": {
360+
"url": "https://image.url/Donald.jog.png",
361+
"width": 33.69418132611637,
362+
"height": "auto",
363+
"redactor-attributes": {
364+
"asset_uid": "47f1aa5ae422cd1"
365+
}
366+
},
367+
"children": [
368+
{
369+
"text": ""
370+
}
371+
]
372+
}
373+
],
374+
type: "doc"
375+
}
376+
351377
const paragraphJson = {
352378
uid: "0d7fd",
353379
_version: 13,
@@ -610,6 +636,51 @@ const linkInPJson = {
610636
type: "doc"
611637
}
612638

639+
640+
const linkInPJsonUrl = {
641+
uid: "06e34a7190849d7f2acd",
642+
_version: 13,
643+
attrs: {},
644+
children: [
645+
{
646+
"type": "ps",
647+
"attrs": {
648+
"style": {
649+
"text-align": "left"
650+
},
651+
"redactor-attributes": {}
652+
},
653+
"uid": "d88dcdf4590dff2d",
654+
"children": [
655+
{
656+
"text": "",
657+
"bold": true,
658+
"italic": true,
659+
"underline": true,
660+
"subscript": true
661+
},
662+
{
663+
"uid": "0d06598201aa8b47",
664+
"type": "a",
665+
"attrs": {
666+
"url": "LINK.com",
667+
"target": "_self"
668+
},
669+
"children": [
670+
{
671+
"text": "LINK"
672+
}
673+
]
674+
},
675+
{
676+
"text": ""
677+
}
678+
]
679+
}
680+
],
681+
type: "doc"
682+
}
683+
613684
const assetReferenceJson = {
614685
uid: "node_uid_12",
615686
_version: 1,
@@ -954,9 +1025,11 @@ export {
9541025
h5Json,
9551026
h6Json,
9561027
imgJson,
1028+
imgJsonURL,
9571029
codeJson,
9581030
tableJson,
9591031
linkInPJson,
1032+
linkInPJsonUrl,
9601033
plainTextJson,
9611034
paragraphJson,
9621035
orderListJson,

src/options/default-node-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export const defaultNodeOption: RenderOption = {
1111
return `<p>${next(node.children)}</p>`
1212
},
1313
[NodeType.LINK]:(node: Node, next: Next) => {
14-
return `<a href="${node.attrs.href}">${next(node.children)}</a>`
14+
return `<a href="${node.attrs.href || node.attrs.url}">${next(node.children)}</a>`
1515
},
1616
[NodeType.IMAGE]:(node: Node, next: Next) => {
17-
return `<img src="${node.attrs.src}" />${next(node.children)}`
17+
return `<img src="${node.attrs.src || node.attrs.url}" />${next(node.children)}`
1818
},
1919
[NodeType.EMBED]:(node: Node, next: Next) => {
20-
return `<iframe src="${node.attrs.src}">${next(node.children)}</iframe>`
20+
return `<iframe src="${node.attrs.src || node.attrs.url}">${next(node.children)}</iframe>`
2121
},
2222
[NodeType.HEADING_1]:(node: Node, next: Next) => {
2323
return `<h1>${next(node.children)}</h1>`

0 commit comments

Comments
 (0)