當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。