Use full href if parsing URL fails
This commit is contained in:
parent
528a3cd744
commit
0353c6c221
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue