当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript URLExt.isLocal方法代码示例

本文整理汇总了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);
 });
开发者ID:willingc,项目名称:jupyterlab,代码行数:12,代码来源:url.spec.ts

示例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, '');
     });
 }
开发者ID:jupyter,项目名称:jupyterlab,代码行数:36,代码来源:renderers.ts

示例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';
      }
    }
  }
开发者ID:jupyter,项目名称:jupyterlab,代码行数:34,代码来源:renderers.ts

示例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';
      }
    }
  }
开发者ID:blink1073,项目名称:jupyterlab,代码行数:27,代码来源:renderers.ts

示例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 => {
开发者ID:cameronoelsen,项目名称:jupyterlab,代码行数:8,代码来源:renderers.ts

示例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';
     }
   }
 }
开发者ID:cameronoelsen,项目名称:jupyterlab,代码行数:12,代码来源:renderers.ts

示例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 = '';
     });
 }
开发者ID:jupyter,项目名称:jupyterlab,代码行数:52,代码来源:renderers.ts

示例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);
 });
开发者ID:cameronoelsen,项目名称:jupyterlab,代码行数:6,代码来源:url.spec.ts


注:本文中的@jupyterlab/coreutils.URLExt.isLocal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。