Skip to content

Commit b86005b

Browse files
committed
fix: link target issue
1 parent 4c4e16a commit b86005b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

__test__/json-to-html.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
h6Html,
3232
imgHtml,
3333
linkInPHtml,
34+
linkInPURLHtml,
3435
orderListHtml,
3536
paragraphHtml,
3637
plainTextHtml,
@@ -488,7 +489,7 @@ describe('Node parse link in paragraph content', () => {
488489

489490
jsonToHTML({ entry, paths})
490491

491-
expect(entry.supercharged_rte).toEqual([linkInPHtml])
492+
expect(entry.supercharged_rte).toEqual([linkInPURLHtml])
492493
done()
493494
})
494495
})

__test__/mock/json-element-mock-result.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const tableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p>
1313
const blockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>"
1414
const codeHtml = "<code>Code template.</code>"
1515
const linkInPHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a>"
16+
const linkInPURLHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\" target=\"_self\">LINK</a>"
1617

1718
export {
1819
h1Html,
@@ -28,6 +29,7 @@ export {
2829
orderListHtml,
2930
paragraphHtml,
3031
plainTextHtml,
32+
linkInPURLHtml,
3133
blockquoteHtml,
3234
unorderListHtml,
3335
}

__test__/mock/json-element-mock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,7 @@ const linkInPJson = {
619619
"uid": "0d06598201aa8b47",
620620
"type": "a",
621621
"attrs": {
622-
"href": "LINK.com",
623-
"target": "_self"
622+
"href": "LINK.com"
624623
},
625624
"children": [
626625
{

src/options/default-node-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export const defaultNodeOption: RenderOption = {
1111
return `<p>${next(node.children)}</p>`
1212
},
1313
[NodeType.LINK]:(node: Node, next: Next) => {
14+
if (node.attrs.target) {
15+
return `<a href="${node.attrs.href || node.attrs.url}" target="${node.attrs.target}">${next(node.children)}</a>`
16+
}
1417
return `<a href="${node.attrs.href || node.attrs.url}">${next(node.children)}</a>`
1518
},
1619
[NodeType.IMAGE]:(node: Node, next: Next) => {

0 commit comments

Comments
 (0)