本文整理汇总了TypeScript中@jupyterlab/coreutils.URLExt.isLocal方法的典型用法代码示例。如果您正苦于以下问题:TypeScript URLExt.isLocal方法的具体用法?TypeScript URLExt.isLocal怎么用?TypeScript URLExt.isLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/coreutils.URLExt
的用法示例。
在下文中一共展示了URLExt.isLocal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should test whether the url is a local url', () => {
expect(URLExt.isLocal('https://foo/bar.txt')).to.equal(false);
expect(URLExt.isLocal('http://foo/bar.txt')).to.equal(false);
expect(URLExt.isLocal('//foo/bar.txt')).to.equal(false);
expect(URLExt.isLocal('../foo/bar.txt')).to.equal(true);
expect(URLExt.isLocal('./foo/bar.txt')).to.equal(true);
expect(URLExt.isLocal('/foo/bar.txt')).to.equal(true);
expect(URLExt.isLocal('foo/bar.txt')).to.equal(true);
expect(URLExt.isLocal('bar.txt')).to.equal(true);
expect(URLExt.isLocal('file://foo/bar.txt')).to.equal(false);
expect(URLExt.isLocal('data:text/plain,123ABC')).to.equal(false);
});
示例2: handleAttr
/**
* Handle a node with a `src` or `href` attribute.
*/
function handleAttr(
node: HTMLElement,
name: 'src' | 'href',
resolver: IRenderMime.IResolver
): Promise<void> {
let source = node.getAttribute(name) || '';
const isLocal = resolver.isLocal
? resolver.isLocal(source)
: URLExt.isLocal(source);
if (!source || !isLocal) {
return Promise.resolve(undefined);
}
node.setAttribute(name, '');
return resolver
.resolveUrl(source)
.then(urlPath => {
return resolver.getDownloadUrl(urlPath);
})
.then(url => {
// Check protocol again in case it changed:
if (URLExt.parse(url).protocol !== 'data:') {
// Bust caching for local src attrs.
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache
url += (/\?/.test(url) ? '&' : '?') + new Date().getTime();
}
node.setAttribute(name, url);
})
.catch(err => {
// If there was an error getting the url,
// just make it an empty link.
node.setAttribute(name, '');
});
}
示例3: handleDefaults
export function handleDefaults(
node: HTMLElement,
resolver?: IRenderMime.IResolver
): void {
// Handle anchor elements.
let anchors = node.getElementsByTagName('a');
for (let i = 0; i < anchors.length; i++) {
const el = anchors[i];
// skip when processing a elements inside svg
// which are of type SVGAnimatedString
if (!(el instanceof HTMLAnchorElement)) {
continue;
}
let path = el.href;
const isLocal =
resolver && resolver.isLocal
? resolver.isLocal(path)
: URLExt.isLocal(path);
if (isLocal) {
el.target = '_self';
} else {
el.target = '_blank';
el.rel = 'noopener';
}
}
// Handle image elements.
let imgs = node.getElementsByTagName('img');
for (let i = 0; i < imgs.length; i++) {
if (!imgs[i].alt) {
imgs[i].alt = 'Image';
}
}
}
示例4: handleDefaults
export function handleDefaults(
node: HTMLElement,
resolver?: IRenderMime.IResolver
): void {
// Handle anchor elements.
let anchors = node.getElementsByTagName('a');
for (let i = 0; i < anchors.length; i++) {
let path = anchors[i].href || '';
const isLocal =
resolver && resolver.isLocal
? resolver.isLocal(path)
: URLExt.isLocal(path);
if (isLocal) {
anchors[i].target = '_self';
} else {
anchors[i].target = '_blank';
}
}
// Handle image elements.
let imgs = node.getElementsByTagName('img');
for (let i = 0; i < imgs.length; i++) {
if (!imgs[i].alt) {
imgs[i].alt = 'Image';
}
}
}
示例5:
return resolver.resolveUrl(href).then(path => {
// Handle the click override.
if (linkHandler && URLExt.isLocal(path)) {
linkHandler.handleLink(anchor, path);
}
// Get the appropriate file download path.
return resolver.getDownloadUrl(path);
}).then(url => {
示例6: handleDefaults
function handleDefaults(node: HTMLElement): void {
// Handle anchor elements.
let anchors = node.getElementsByTagName('a');
for (let i = 0; i < anchors.length; i++) {
let path = anchors[i].href;
if (URLExt.isLocal(path)) {
anchors[i].target = '_self';
} else {
anchors[i].target = '_blank';
}
}
}
示例7: handleAnchor
/**
* Handle an anchor node.
*/
function handleAnchor(
anchor: HTMLAnchorElement,
resolver: IRenderMime.IResolver,
linkHandler: IRenderMime.ILinkHandler | null
): Promise<void> {
// Get the link path without the location prepended.
// (e.g. "./foo.md#Header 1" vs "http://localhost:8888/foo.md#Header 1")
let href = anchor.getAttribute('href') || '';
const isLocal = resolver.isLocal
? resolver.isLocal(href)
: URLExt.isLocal(href);
// Bail if it is not a file-like url.
if (!href || !isLocal) {
return Promise.resolve(undefined);
}
// Remove the hash until we can handle it.
let hash = anchor.hash;
if (hash) {
// Handle internal link in the file.
if (hash === href) {
anchor.target = '_self';
return Promise.resolve(undefined);
}
// For external links, remove the hash until we have hash handling.
href = href.replace(hash, '');
}
// Get the appropriate file path.
return resolver
.resolveUrl(href)
.then(urlPath => {
// decode encoded url from url to api path
const path = decodeURI(urlPath);
// Handle the click override.
if (linkHandler) {
linkHandler.handleLink(anchor, path, hash);
}
// Get the appropriate file download path.
return resolver.getDownloadUrl(urlPath);
})
.then(url => {
// Set the visible anchor.
anchor.href = url + hash;
})
.catch(err => {
// If there was an error getting the url,
// just make it an empty link.
anchor.href = '';
});
}
示例8: it
it('should test whether the url is a local url', () => {
expect(URLExt.isLocal('//foo')).to.equal(false);
expect(URLExt.isLocal('http://foo')).to.equal(false);
expect(URLExt.isLocal('/foo/bar')).to.equal(true);
expect(URLExt.isLocal('foo.txt')).to.equal(true);
});