diff --git a/src/core/render/compiler/link.js b/src/core/render/compiler/link.js index c884b2b90..925e93051 100644 --- a/src/core/render/compiler/link.js +++ b/src/core/render/compiler/link.js @@ -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 = diff --git a/test/integration/render.test.js b/test/integration/render.test.js index 4b6fbc1b3..ad4b81dd0 100644 --- a/test/integration/render.test.js +++ b/test/integration/render.test.js @@ -253,7 +253,7 @@ 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( @@ -261,6 +261,14 @@ describe('render', function () { ); }); + test('target for relative path', async function () { + const output = window.marked("[alt text](/url ':target=_blank')"); + + expect(output).toMatchInlineSnapshot( + `"

alt text

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