mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add target="_blank" attribute to external markdown links
This commit is contained in:
@@ -98,8 +98,14 @@
|
||||
}
|
||||
|
||||
afterUpdate(async () => {
|
||||
// Don't underline <a> tags that contain images.
|
||||
for (const e of container.querySelectorAll("a")) {
|
||||
if (URL.canParse(e.href)) {
|
||||
const url = new URL(e.href);
|
||||
if (url.origin !== window.origin) {
|
||||
e.target = "_blank";
|
||||
}
|
||||
}
|
||||
// Don't underline <a> tags that contain images.
|
||||
if (e.firstElementChild instanceof HTMLImageElement) {
|
||||
e.classList.add("no-underline");
|
||||
}
|
||||
|
||||
+4
-5
@@ -140,11 +140,10 @@ export class Renderer extends BaseRenderer {
|
||||
// By lowercasing we avoid casing mismatches, between headings and links.
|
||||
return `<a href="${href.toLowerCase()}">${text}</a>`;
|
||||
} else {
|
||||
try {
|
||||
href = new URL(href, this.#baseUrl).href;
|
||||
} catch {
|
||||
// Use original href value
|
||||
}
|
||||
href = URL.canParse(href, this.#baseUrl)
|
||||
? new URL(href, this.#baseUrl).href
|
||||
: href;
|
||||
|
||||
return `<a href="${href}">${text}</a>`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user