How to use the @jupyterlab/coreutils.URLExt.isLocal function in @jupyterlab/coreutils

To help you get started, we’ve selected a few @jupyterlab/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yuvipanda / simplest-notebook / packages / rendermime / src / renderers.ts View on Github external
function handleAttr(
    node: HTMLElement,
    name: 'src' | 'href',
    resolver: IRenderMime.IResolver
  ): Promise {
    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(path => {
        return resolver.getDownloadUrl(path);
      })
      .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();
        }
github jupyterlab / jupyterlab-data-explorer / packages / rendermime / src / renderers.ts View on Github external
function handleAttr(
    node: HTMLElement,
    name: 'src' | 'href',
    resolver: IRenderMime.IResolver
  ): Promise {
    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();
        }
github dask / dask-labextension / src / dashboard.tsx View on Github external
export function testDaskDashboard(
    url: string,
    settings: ServerConnection.ISettings
  ): Promise {
    url = normalizeDashboardUrl(url);

    // If this is a url that we are proxying under the notebook server,
    // it is easier to check for a valid dashboard.
    if (URLExt.isLocal(url)) {
      return ServerConnection.makeRequest(
        URLExt.join(settings.baseUrl, url, 'individual-plots.json'),
        {},
        settings
      ).then(response => {
        if (response.status === 200) {
          return true;
        } else {
          return false;
        }
      });
    }

    return new Promise(resolve => {
      // Hack Alert! We would like to test whether a given URL is actually
      // a dask dashboard, since we will be iframe-ing it sight-unseen.
github jupyterlab / jupyterlab-data-explorer / packages / rendermime / src / renderers.ts View on Github external
function handleAnchor(
    anchor: HTMLAnchorElement,
    resolver: IRenderMime.IResolver,
    linkHandler: IRenderMime.ILinkHandler | null
  ): Promise {
    // 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.
github yuvipanda / simplest-notebook / packages / rendermime / src / renderers.ts View on Github external
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';
      }
    }
  }
github jupyterlab / jupyterlab-data-explorer / tests / test-coreutils / src / url.spec.ts View on Github external
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('file://foo/bar.txt')).to.equal(false);
        expect(URLExt.isLocal('data:text/plain,123ABC')).to.equal(false);
        expect(URLExt.isLocal('/foo/bar.txt')).to.equal(false);
        expect(URLExt.isLocal('httpserver/index.html')).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);
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-coreutils / src / url.spec.ts View on Github external
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('file://foo/bar.txt')).to.equal(false);
        expect(URLExt.isLocal('data:text/plain,123ABC')).to.equal(false);
        expect(URLExt.isLocal('/foo/bar.txt')).to.equal(false);
        expect(URLExt.isLocal('httpserver/index.html')).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);
      });
    });
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / apputils / src / thememanager.ts View on Github external
loadCSS(path: string): Promise {
    const base = this._base;
    const href = URLExt.isLocal(path) ? URLExt.join(base, path) : path;
    const links = this._links;

    return new Promise((resolve, reject) => {
      const link = document.createElement('link');

      link.setAttribute('rel', 'stylesheet');
      link.setAttribute('type', 'text/css');
      link.setAttribute('href', href);
      link.addEventListener('load', () => {
        resolve(undefined);
      });
      link.addEventListener('error', () => {
        reject(`Stylesheet failed to load: ${href}`);
      });

      document.body.appendChild(link);
github jupyterlab / jupyterlab / packages / rendermime / src / registry.ts View on Github external
isLocal(url: string): boolean {
      const path = decodeURI(url);
      return URLExt.isLocal(url) || !!this._contents.driveName(path);
    }