How to use mdurl - 10 common examples

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 markdown-it / markdown-it / support / demo_template / index.js View on Github external
'.result-debug-content',
      JSON.stringify(mdSrc.parse(source, { references: {} }), null, 2),
      'json'
    );

  } else { /*defaults._view === 'html'*/
    $('.result-html').html(mdHtml.render(source));
  }

  // reset lines mapping cache on content update
  scrollMap = null;

  try {
    if (source) {
      // serialize state - source and options
      permalink.href = '#md3=' + mdurl.encode(JSON.stringify({
        source: source,
        defaults: _.omit(defaults, 'highlight')
      }), '-_.!~', false);
    } else {
      permalink.href = '';
    }
  } catch (__) {
    permalink.href = '';
  }
}
github nodeca / url-unshort / lib / index.js View on Github external
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;
          result = mdurl.format(u);
        }

        return result;
      }
    }

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

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

    // Something found - run additional checks.
github markdown-it / markdown-it / lib / index.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));
}
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 sx1989827 / DOClever / node_modules / markdown-it / lib / index.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));
}

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 sx1989827 / DOClever / node_modules / markdown-it / lib / index.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.toUnicode(parsed.hostname);
      } catch (er) { /**/ }
    }
  }

  return mdurl.decode(mdurl.format(parsed));
}

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));
};

mdurl

URL utilities for markdown-it

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Similar packages