Skip to content

Commit

Permalink
feat: support relative path with target config. (#1751)
Browse files Browse the repository at this point in the history
Co-authored-by: John Hildenbiddle <jhildenbiddle@users.noreply.github.com>
Co-authored-by: Joe Pea <joe@trusktr.io>
  • Loading branch information
3 people committed Apr 28, 2024
1 parent bb902f8 commit e15ad0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit e15ad0c

Please sign in to comment.