How to use snapdragon-util - 10 common examples

To help you get started, we’ve selected a few snapdragon-util 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 breakdance / breakdance / lib / compiler.js View on Github external
// run any registered "after" plugins
      node = after.call(this, node) || node;
      return node;
    };

    /**
     * Snapdragon compilers
     */

    compiler

      /**
       * Beginning of string
       */

      .set('bos', util.noop)

      /**
       * Directives and comments
       */

      .set('doctype', util.noop)
      .set('comment', function(node) {
        if (this.options.comments === true) {
          this.emit('');
        }
      })

      /**
       * Root element 
       */
github breakdance / breakdance / lib / utils.js View on Github external
return function(node, nodes, i) {
    if (util.isEmptyNodes(node, open)) return;
    var state = this.state;
    var type = node.type;
    var isVoid = isSelfClosing(node.type);

    if (!isVoid && !this.compilers.hasOwnProperty(type + '.open')) {
      this.set(type + '.open', util.noop);
      this.set(type + '.close', util.noop);
    }

    // convert headings to bold see: edge-cases.md - headings #1
    if (/^h[1-6]$/.test(type)) {
      if (util.isInside(state, node, ['a', 'li', 'table'])) {
        node.type = 'strong';
        open = '**';
        close = '**';
      }
    }

    if (typeof visitor === 'function') {
      visitor.call(this, node, nodes, i);

      // allow visitor to override opening tag
      if (node.open) {
github breakdance / breakdance / lib / utils.js View on Github external
return function(node, nodes, i) {
    if (util.isEmptyNodes(node, open)) return;
    var state = this.state;
    var type = node.type;
    var isVoid = isSelfClosing(node.type);

    if (!isVoid && !this.compilers.hasOwnProperty(type + '.open')) {
      this.set(type + '.open', util.noop);
      this.set(type + '.close', util.noop);
    }

    // convert headings to bold see: edge-cases.md - headings #1
    if (/^h[1-6]$/.test(type)) {
      if (util.isInside(state, node, ['a', 'li', 'table'])) {
        node.type = 'strong';
        open = '**';
        close = '**';
      }
    }

    if (typeof visitor === 'function') {
      visitor.call(this, node, nodes, i);

      // allow visitor to override opening tag
github breakdance / breakdance / lib / utils.js View on Github external
return function(node, nodes, i) {
    if (util.isEmptyNodes(node, open)) return;
    var state = this.state;
    var type = node.type;
    var isVoid = isSelfClosing(node.type);

    if (!isVoid && !this.compilers.hasOwnProperty(type + '.open')) {
      this.set(type + '.open', util.noop);
      this.set(type + '.close', util.noop);
    }

    // convert headings to bold see: edge-cases.md - headings #1
    if (/^h[1-6]$/.test(type)) {
      if (util.isInside(state, node, ['a', 'li', 'table'])) {
        node.type = 'strong';
        open = '**';
        close = '**';
      }
github breakdance / breakdance / lib / utils.js View on Github external
return function(node, nodes, i) {
    if (util.isEmptyNodes(node, open)) return;
    var state = this.state;
    var type = node.type;
    var isVoid = isSelfClosing(node.type);

    if (!isVoid && !this.compilers.hasOwnProperty(type + '.open')) {
      this.set(type + '.open', util.noop);
      this.set(type + '.close', util.noop);
    }

    // convert headings to bold see: edge-cases.md - headings #1
    if (/^h[1-6]$/.test(type)) {
      if (util.isInside(state, node, ['a', 'li', 'table'])) {
        node.type = 'strong';
        open = '**';
        close = '**';
      }
    }

    if (typeof visitor === 'function') {
      visitor.call(this, node, nodes, i);

      // allow visitor to override opening tag
      if (node.open) {
        open = node.open;
      }
    }

    if (!/^(sup|sub)$/.test(node.type) && /[a-z0-9]/i.test(this.output.slice(-1))) {
github breakdance / breakdance / lib / tables.js View on Github external
function combineRows(ast) {
  var thead = util.firstOfType(ast.nodes, 'thead');

  if (!thead) return;

  var rows = thead.nodes.filter(function(node) {
    return node.type === 'tr';
  });

  if (rows.length === 1) return;

  // handle `` (no ``)
  if (rows.length === 0) {
    var i = 1;
    var e = thead.nodes.length - 1;
    if (thead.nodes[i].type === 'text') i++;
    if (thead.nodes[e].type === 'text') e--;
github breakdance / breakdance / lib / compiler.js View on Github external
// register a noop handler if an unrecognized HTML element is encountered
      if (!this.compilers[node.type] && this.options.knownOnly !== true) {
        this.set(node.type, util.noop);
      }

      var compilerOpts = this.options.compiler || {};
      var visitor = compilerOpts[node.type];
      if (visitor === false) {
        return;
      }

      // run any registered "before" plugins
      node = before.call(this, node) || node;

      // add or remove this node type from `state.types`
      if (util.isOpen(node)) util.addType(this.state, node);
      if (util.isClose(node)) util.removeType(this.state, node);

      if (typeof visitor === 'function') {
        node = visitor.apply(this, arguments) || node;
      } else {
        node = visit.apply(this, arguments) || node;
      }

      // run any registered "after" plugins
      node = after.call(this, node) || node;
      return node;
    };
github breakdance / breakdance / lib / compiler.js View on Github external
if (!this.compilers[node.type] && this.options.knownOnly !== true) {
        this.set(node.type, util.noop);
      }

      var compilerOpts = this.options.compiler || {};
      var visitor = compilerOpts[node.type];
      if (visitor === false) {
        return;
      }

      // run any registered "before" plugins
      node = before.call(this, node) || node;

      // add or remove this node type from `state.types`
      if (util.isOpen(node)) util.addType(this.state, node);
      if (util.isClose(node)) util.removeType(this.state, node);

      if (typeof visitor === 'function') {
        node = visitor.apply(this, arguments) || node;
      } else {
        node = visit.apply(this, arguments) || node;
      }

      // run any registered "after" plugins
      node = after.call(this, node) || node;
      return node;
    };
github breakdance / breakdance / lib / compiler.js View on Github external
}

        node.delim = /`/.test(node.text) ? '``' : '`';
        if (node.html) {
          var type = node.parent.type;
          node.lang = type === 'pre' ? utils.getLang(node.attribs) : '';
          var text = {type: 'text', val: unescape(node.html)};
          if (node.lang) {
            text.val = node.text;
          }

          define(text, 'parent', node);
          define(text, 'prev', {});
          define(text, 'next', {});
          node.nodes = [text];
          util.wrapNodes(node, Node);
        }
        this.mapVisit(node);
      })
      .set('code.open', function(node) {
github breakdance / breakdance / lib / handlers / pre.js View on Github external
return function(node, nodes, i) {
    var opts = extend({}, this.options, options);
    var replaceRe = /(?:lang(uage)?|highlight|source|brush:\s*)[-]?| /g;
    var testRe = /(?:lang(uage)?|highlight|source|brush:\s*)/;

    var pre = opts.literalPre || !util.hasType(node, 'code');
    if (pre) {
      node.lang = (node.attr && node.attr['data-lang']) || '';
      var attribs = node.attribs;

      if (!node.lang && attribs && attribs.class) {
        var cls = attribs.class;
        if (cls && testRe.test(cls)) {
          node.lang = cls.replace(replaceRe, '');
        }
      }

      var parent = node.parent || {};
      if (!node.lang && parent && parent.attribs) {
        cls = parent.attribs.class;
        if (cls && testRe.test(cls)) {
          node.lang = cls.replace(replaceRe, '');