Skip to content

Commit 9abd508

Browse files
Merge pull request #136 from MaddyGuthridge/maddy-md-new-tab
Markdown render: only open links in a new tab if they point to a different page
2 parents 38831f0 + 6bf4e18 commit 9abd508

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minifolio",
3-
"version": "1.1.10",
3+
"version": "1.1.11",
44
"private": true,
55
"license": "GPL-3.0-only",
66
"scripts": {

src/components/markdown/Markdown.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
const renderer = {
1818
link(options: Tokens.Link) {
1919
const link = marked.Renderer.prototype.link.call(this, options);
20-
return link.replace('<a', "<a target='_blank' rel='noreferrer' ");
20+
// Only make links open in a new tab if they point to a different page
21+
if (options.href.startsWith('#')) {
22+
return link;
23+
} else {
24+
return link.replace('<a', "<a target='_blank' rel='noreferrer' ");
25+
}
2126
},
2227
};
2328
marked.use(gfmHeadingId(), customHeadingId(), { renderer });

0 commit comments

Comments
 (0)