Skip to content

Commit e15ad0c

Browse files
Koooooo-7jhildenbiddletrusktr
authored
feat: support relative path with target config. (#1751)
Co-authored-by: John Hildenbiddle <[email protected]> Co-authored-by: Joe Pea <[email protected]>
1 parent bb902f8 commit e15ad0c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/render/compiler/link.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const linkCompiler = ({
2828
}
2929

3030
href = router.toURL(href, null, router.getCurrentPath());
31+
32+
if (config.target) {
33+
href.indexOf('mailto:') !== 0 && attrs.push(`target="${linkTarget}"`);
34+
}
3135
} else {
3236
if (!isAbsolutePath(href) && href.slice(0, 2) === './') {
3337
href =

test/integration/render.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,22 @@ describe('render', function () {
253253
);
254254
});
255255

256-
test('target', async function () {
256+
test('target for absolute path', async function () {
257257
const output = window.marked("[alt text](http://url ':target=_self')");
258258

259259
expect(output).toMatchInlineSnapshot(
260260
`"<p><a href=\\"http://url\\" target=\\"_self\\" >alt text</a></p>"`
261261
);
262262
});
263263

264+
test('target for relative path', async function () {
265+
const output = window.marked("[alt text](/url ':target=_blank')");
266+
267+
expect(output).toMatchInlineSnapshot(
268+
`"<p><a href=\\"#/url\\" target=\\"_blank\\">alt text</a></p>"`
269+
);
270+
});
271+
264272
test('class', async function () {
265273
const output = window.marked(
266274
"[alt text](http://url ':class=someCssClass')"

0 commit comments

Comments
 (0)