Skip to content

Commit

Permalink
prettier, fix, updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernard Xie authored and gavin-ts committed Nov 28, 2023
1 parent bfde775 commit 897a959
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,23 @@ export class D2Processor {
await debouncedFunc(source, el, ctx, newAbortController.signal);
};

isValidUrl = (urlString: string) => {
let url;
try {
url = new URL(urlString);
} catch (e) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
};

formatLinks = (svgEl: HTMLElement) => {
// Add attributes to <a> tags to make them Obsidian compatible :
const links = svgEl.querySelectorAll("a");
links.forEach((link: HTMLElement) => {
const href = link.getAttribute("href")??""
const href = link.getAttribute("href") ?? "";
// Check for internal link
if (!href.match(/:\/\//g)){
if (!this.isValidUrl(href)) {
link.classList.add("internal-link");
link.setAttribute("data-href", href);
link.setAttribute("target", "_blank");
Expand Down

0 comments on commit 897a959

Please sign in to comment.