How to use the mdurl.decode 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 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 nodeca / nodeca.core / lib / parser / beautify_url.js View on Github external
var url = mdurl.parse(String(url_str), true);

  // urls without host and protocol, e.g. "example.org/foo"
  if (!url.protocol && !url.slashes && !url.hostname) {
    url = mdurl.parse('//' + url_str, true);
  }

  try {
    if (url.hostname) {
      url.hostname = punycode.toUnicode(url.hostname);
    }
  } catch (e) {}

  // Decode url-encoded characters
  //
  if (url.auth)     url.auth     = mdurl.decode(url.auth);
  if (url.hash)     url.hash     = mdurl.decode(url.hash);
  if (url.search)   url.search   = mdurl.decode(url.search);
  if (url.pathname) url.pathname = mdurl.decode(url.pathname);

  // Omit protocol if it's http, https or mailto
  //
  if (url.protocol && url.protocol.match(/^(https?|mailto):$/)) {
    url.protocol = null;
    url.slashes = null;
  } else if (url.slashes) {
    url.slashes = null;
  }

  return elide_url(url, max_length);
}
github nodeca / nodeca.core / lib / parser / beautify_url.js View on Github external
// urls without host and protocol, e.g. "example.org/foo"
  if (!url.protocol && !url.slashes && !url.hostname) {
    url = mdurl.parse('//' + url_str, true);
  }

  try {
    if (url.hostname) {
      url.hostname = punycode.toUnicode(url.hostname);
    }
  } catch (e) {}

  // Decode url-encoded characters
  //
  if (url.auth)     url.auth     = mdurl.decode(url.auth);
  if (url.hash)     url.hash     = mdurl.decode(url.hash);
  if (url.search)   url.search   = mdurl.decode(url.search);
  if (url.pathname) url.pathname = mdurl.decode(url.pathname);

  // Omit protocol if it's http, https or mailto
  //
  if (url.protocol && url.protocol.match(/^(https?|mailto):$/)) {
    url.protocol = null;
    url.slashes = null;
  } else if (url.slashes) {
    url.slashes = null;
  }

  return elide_url(url, max_length);
}
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.toUnicode(parsed.hostname);
      } catch (er) { /**/ }
    }
  }

  return mdurl.decode(mdurl.format(parsed));
}
github markdown-it / markdown-it / support / demo_template / index.js View on Github external
function loadPermalink() {

  if (!location.hash) { return; }

  var cfg, opts;

  try {

    if (/^#md3=/.test(location.hash)) {
      cfg = JSON.parse(mdurl.decode(location.hash.slice(5), mdurl.decode.componentChars));

    } else if (/^#md64=/.test(location.hash)) {
      cfg = JSON.parse(window.atob(location.hash.slice(6)));

    } else if (/^#md=/.test(location.hash)) {
      cfg = JSON.parse(decodeURIComponent(location.hash.slice(4)));

    } else {
      return;
    }

    if (_.isString(cfg.source)) {
      $('.source').val(cfg.source);
    }
  } catch (__) {
    return;
github petrosagg / papagal / src / vendor / markdown-it / lib / index.js View on Github external
function i(e) {
    var t = f.parse(e, true);
    if (t.hostname && (!t.protocol || y.indexOf(t.protocol) >= 0)) {
        try {
            t.hostname = m.toUnicode(t.hostname);
        } catch (n) {}
    }
    return f.decode(f.format(t));
}
github BoostIO / Boostnote / browser / components / MarkdownPreview.js View on Github external
fixDecodedURI (node) {
    if (
      node &&
      node.children.length === 1 &&
      typeof node.children[0] === 'string'
    ) {
      const { innerText, href } = node

      node.innerText = mdurl.decode(href) === innerText ? href : innerText
    }
  }
github BoostIO / Boostnote / browser / components / MarkdownPreview.js View on Github external
fixDecodedURI (node) {
    if (
      node &&
      node.children.length === 1 &&
      typeof node.children[0] === 'string'
    ) {
      const { innerText, href } = node

      node.innerText = mdurl.decode(href) === innerText ? href : innerText
    }
  }

mdurl

URL utilities for markdown-it

MIT
Latest version published 8 months ago

Package Health Score

70 / 100
Full package analysis

Similar packages