Skip to content

Commit eea65bf

Browse files
committed
enhance: support relative path with target config.
1 parent fa6df6d commit eea65bf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/core/render/compiler/link.js

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

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

test/integration/render.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,23 @@ describe('render', function () {
238238
);
239239
});
240240

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

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

249+
test('target for relative path', async function () {
250+
const output = window.marked("[alt text](/url ':target=_blank')");
251+
console.log(output);
252+
253+
expect(output).toMatchInlineSnapshot(
254+
`"<p><a href=\\"#/url\\" target=\\"_blank\\">alt text</a></p>"`
255+
);
256+
});
257+
249258
test('class', async function () {
250259
const output = window.marked(
251260
"[alt text](http://url ':class=someCssClass')"

0 commit comments

Comments
 (0)