Use full href if parsing URL fails

This commit is contained in:
Shadowfacts 2019-11-10 22:36:02 -05:00
parent 528a3cd744
commit 0353c6c221
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 2 additions and 2 deletions

View File

@ -58,14 +58,14 @@ md.renderer.rules.link_open = function(tokens, index, options, env, self) {
if (href != null) {
try {
const parsed = new URL(href);
const formattedPathname = parsed.pathname === "/" ? "" : parsed.pathname;//.length > 20 ? parsed.pathname.substr(0, 20) + "..." : parsed.pathname;
const formattedPathname = parsed.pathname === "/" ? "" : parsed.pathname;
let formatted = `${parsed.hostname}${formattedPathname}`;
if (formatted.length > 40) {
formatted = formatted.substr(0, 40) + "...";
}
tokens[index].attrPush(["data-link", formatted]);
} catch (e) {
// URL constructor throws on invalid URLs (such as ones that only contain a fragment), so swallow those exceptions
tokens[index].attrPush(["data-link", href]);
}
}