Skip to content

Commit d45e564

Browse files
committed
Add target=_blank to external links
1 parent 5a95323 commit d45e564

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

web/scripts/build.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ async function buildVersionMenu(versions, currentVersion) {
9898
}
9999

100100
const marked = new Marked();
101+
const customRenderer = {
102+
link({ href, text }) {
103+
const isExternal = /^https?:\/\//.test(href);
104+
let html = `<a href="${href}"`;
105+
if (isExternal) html += ' target="_blank"';
106+
html += `>${text}</a>`;
107+
return html;
108+
}
109+
};
110+
marked.use({ renderer: customRenderer });
101111

102112
let blogMenu = '';
103113
async function buildBlogMenu() {
@@ -137,6 +147,7 @@ async function build() {
137147
let htmlFileName = '';
138148

139149
const markedWithContents = new Marked();
150+
markedWithContents.use({ renderer: customRenderer });
140151
markedWithContents.use(gfmHeadingId({ prefix: 'block-' }), {
141152
hooks: {
142153
postprocess(html) {

0 commit comments

Comments
 (0)