From fff477e683adf483a4550a9deba80655c2c646d6 Mon Sep 17 00:00:00 2001 From: confused_techie Date: Fri, 27 Oct 2023 08:47:10 -0700 Subject: [PATCH] Don't modify base64 images, strip ending slash in all links, fix href links to use `blob` URLs --- src/ui.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ui.js b/src/ui.js index 7270161cf6..5762f83f5c 100644 --- a/src/ui.js +++ b/src/ui.js @@ -62,7 +62,8 @@ function renderMarkdown(content, givenOpts = {}) { }; const cleanRootDomain = () => { - return opts.rootDomain.replace(".git", ""); + // We will also remove any trailing `/` as link resolvers down the line add them in + return opts.rootDomain.replace(".git", "").replace(/\/$/, ""); }; const markdownItOpts = { @@ -137,7 +138,7 @@ function renderMarkdown(content, givenOpts = {}) { } else { token.attrSet("src", `${cleanRootDomain()}/raw/HEAD/${rawLink}`); } - } else if (!token.attrGet("src").startsWith("http")) { + } else if (!token.attrGet("src").startsWith("http") && !mdComponents.reg.globalLinks.base64.test(token.attrGet("src"))) { // Check for implicit relative urls let rawLink = token.attrGet("src"); token.attrSet("src", `${cleanRootDomain()}/raw/HEAD/${rawLink}`); @@ -165,11 +166,11 @@ function renderMarkdown(content, givenOpts = {}) { // Fix any links that attempt to point to packages on `https://atom.io/packages/...` attr[1] = `https://web.pulsar-edit.dev/packages/${link.match(mdComponents.reg.atomLinks.package)[1]}`; } else if (opts.transformNonFqdnLinks && mdComponents.reg.localLinks.currentDir.test(link)) { - attr[1] = `${cleanRootDomain().replace(/\/$/, "")}/raw/HEAD/${link.replace(mdComponents.reg.localLinks.currentDir, "")}`; + attr[1] = `${cleanRootDomain()}/blob/HEAD/${link.replace(mdComponents.reg.localLinks.currentDir, "")}`; } else if (opts.transformNonFqdnLinks && mdComponents.reg.localLinks.rootDir.test(link)) { - attr[1] = `${cleanRootDomain().replace(/\/$/, "")}/raw/HEAD/${link.replace(mdComponents.reg.localLinks.rootDir, "")}`; - } else if (opts.transformNonFqdnLinks && !link.startsWith("http") && !mdComponents.reg.globalLinks.base64.test(link)) { - attr[1] = `${cleanRootDomain().replace(/\/$/, "")}/raw/HEAD/${link.replace(".git", "")}`; + attr[1] = `${cleanRootDomain()}/blob/HEAD/${link.replace(mdComponents.reg.localLinks.rootDir, "")}`; + } else if (opts.transformNonFqdnLinks && !link.startsWith("http")) { + attr[1] = `${cleanRootDomain()}/blob/HEAD/${link.replace(".git", "")}`; } else if (opts.transformAtomLinks && mdComponents.reg.atomLinks.flightManual.test(link)) { // Resolve any links to the flight manual to web archive attr[1] = link.replace(mdComponents.reg.atomLinks.flightManual, "https://web.archive.org/web/20221215003438/https://flight-manual.atom.io/");