Skip to content
4 changes: 4 additions & 0 deletions src/core/render/compiler/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const linkCompiler = ({
}

href = router.toURL(href, null, router.getCurrentPath());

if (config.target) {
href.indexOf('mailto:') !== 0 && attrs.push(`target="${linkTarget}"`);
}
} else {
if (!isAbsolutePath(href) && href.slice(0, 2) === './') {
href =
Expand Down
10 changes: 9 additions & 1 deletion test/integration/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,22 @@ describe('render', function () {
);
});

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

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

test('target for relative path', async function () {
const output = window.marked("[alt text](/url ':target=_blank')");

expect(output).toMatchInlineSnapshot(
`"<p><a href=\\"#/url\\" target=\\"_blank\\">alt text</a></p>"`
);
});

test('class', async function () {
const output = window.marked(
"[alt text](http://url ':class=someCssClass')"
Expand Down