How to use the mdurl.format function in mdurl

To help you get started, we’ve selected a few mdurl 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 nodeca / url-unshort / lib / index.js View on Github external
//
    // At top level try cache first. On recursive calls skip cache.
    // !! Cache should be probed even for disabled services, to resolve old links.
    //
    let result;

    if (nestingLeft === this.nesting) {
      result = await this.cache.get(url_normalized);

      // If cache exists - use it.
      if (result || result === null) {
        // forward hash if needed
        if (hash && result) {
          u = mdurl.parse(result, true);
          u.hash = u.hash || hash;
          result = mdurl.format(u);
        }

        return result;
      }
    }

    //
    // First pass validation (quick).
    //

    if (!this._matchAllRE.test(url_normalized)) break;

    // Something found - run additional checks.

    let domainConfig = this._domains.find(dc => dc._compiledMatch.exec(url_normalized));
github nodeca / url-unshort / lib / index.js View on Github external
if (nestingLeft < 0) {
    throw new UnshortError('Too many redirects', 'EBADREDIRECT');
  }

  let result = (url !== origUrl) ? url : null;

  if (shouldCache) {
    // Cache result.
    // !! use normalized original URL for cache key.
    let uo = mdurl.parse(origUrl, true);

    uo.hash = '';
    uo.protocol = uo.protocol || 'http';

    await this.cache.set(mdurl.format(uo), result);
  }

  return result;
};
github MarkBind / markbind / src / lib / markbind / src / lib / markdown-it / normalizeLink.js View on Github external
if (parsed.hostname) {
    // Encode hostnames in urls like:
    // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
    //
    // We don't encode unknown schemas, because it's likely that we encode
    // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
    //
    if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
      try {
        parsed.hostname = punycode.toASCII(parsed.hostname);
      } catch (er) { /**/ }
    }
  }

  return mdurl.encode(mdurl.format(parsed));
}
module.exports = normalizeLink;
github nodeca / url-unshort / lib / index.js View on Github external
if (!u.protocol) {
      // set protocol for relative links like `//example.com`
      u.protocol = 'http:';
    }

    // user-submitted url has weird protocol, just return `null` in this case
    if (u.protocol !== 'http:' && u.protocol !== 'https:') break;

    if (u.hash) {
      // Copying browser-like behavior here: if we're not redirected to a hash,
      // but original url has one, set it as a final hash.
      hash = u.hash;
      u.hash = '';
    }

    let url_normalized = mdurl.format(u);

    //
    // At top level try cache first. On recursive calls skip cache.
    // !! Cache should be probed even for disabled services, to resolve old links.
    //
    let result;

    if (nestingLeft === this.nesting) {
      result = await this.cache.get(url_normalized);

      // If cache exists - use it.
      if (result || result === null) {
        // forward hash if needed
        if (hash && result) {
          u = mdurl.parse(result, true);
          u.hash = u.hash || hash;
github christianvoigt / argdown / packages / argdown-core / src / utils.ts View on Github external
// Encode hostnames in urls like:
    // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
    //
    // We don't encode unknown schemas, because it's likely that we encode
    // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
    //
    if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
      try {
        parsed.hostname = punycode.toASCII(parsed.hostname);
      } catch (er) {
        /**/
      }
    }
  }

  return mdurl.encode(mdurl.format(parsed));
};
github nodeca / nodeca.core / lib / parser / beautify_url.js View on Github external
url.hostname = subdomains.join('.');
      url_str = mdurl.format(url);

      if (text_length(url_str) <= max_path_length) return elide_text(url_str, max);
    }

    while (subdomains.length > 2) {
      subdomains.shift();
      url.hostname = '…' + subdomains.join('.');
      url_str = mdurl.format(url);

      if (text_length(url_str) <= max_path_length) return elide_text(url_str, max);
    }
  }

  return elide_text(mdurl.format(url), max);
}

mdurl

URL utilities for markdown-it

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Similar packages