Skip URL parsing when rendering empty links in Notebooks. (#6889)

This commit is contained in:
Cory Rivera
2019-08-23 14:51:01 -07:00
committed by GitHub
parent 9b7a7bd9dc
commit d6950fa4b7

View File

@@ -478,10 +478,7 @@ namespace Private {
let anchors = node.getElementsByTagName('a'); let anchors = node.getElementsByTagName('a');
for (let i = 0; i < anchors.length; i++) { for (let i = 0; i < anchors.length; i++) {
let path = anchors[i].href || ''; let path = anchors[i].href || '';
const isLocal = let isLocal = isPathLocal(path, resolver);
resolver && resolver.isLocal
? resolver.isLocal(path)
: URLExt.isLocal(path);
if (isLocal) { if (isLocal) {
anchors[i].target = '_self'; anchors[i].target = '_self';
} else { } else {
@@ -568,9 +565,7 @@ namespace Private {
resolver: IRenderMime.IResolver resolver: IRenderMime.IResolver
): Promise<void> { ): Promise<void> {
let source = node.getAttribute(name) || ''; let source = node.getAttribute(name) || '';
const isLocal = resolver.isLocal let isLocal = isPathLocal(source, resolver);
? resolver.isLocal(source)
: URLExt.isLocal(source);
if (!source || !isLocal) { if (!source || !isLocal) {
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
@@ -607,9 +602,7 @@ namespace Private {
// Get the link path without the location prepended. // Get the link path without the location prepended.
// (e.g. "./foo.md#Header 1" vs "http://localhost:8888/foo.md#Header 1") // (e.g. "./foo.md#Header 1" vs "http://localhost:8888/foo.md#Header 1")
let href = anchor.getAttribute('href') || ''; let href = anchor.getAttribute('href') || '';
const isLocal = resolver.isLocal let isLocal = isPathLocal(href, resolver);
? resolver.isLocal(href)
: URLExt.isLocal(href);
// Bail if it is not a file-like url. // Bail if it is not a file-like url.
if (!href || !isLocal) { if (!href || !isLocal) {
return Promise.resolve(undefined); return Promise.resolve(undefined);
@@ -646,4 +639,17 @@ namespace Private {
anchor.href = ''; anchor.href = '';
}); });
} }
function isPathLocal(path: string, resolver: IRenderMime.IResolver): boolean {
let isLocal: boolean;
if (path && path.length > 0) {
isLocal = resolver && resolver.isLocal
? resolver.isLocal(path)
: URLExt.isLocal(path);
} else {
// Empty string, so default to local
isLocal = true;
}
return isLocal;
}
} }