How to use the snapdragon-util.firstOfType function in snapdragon-util

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 / 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 / tables.js View on Github external
function tfootNodes(ast) {
  var nodes = [];
  var tfoot;

  for (var i = 0; i < ast.nodes.length; i++) {
    var node = ast.nodes[i];
    if (node.type === 'tfoot') {
      tfoot = node.nodes;
    } else {
      nodes.push(node);
    }
  }

  if (tfoot) {
    var tbody = util.firstOfType(ast.nodes, 'tbody');
    if (tbody) {
      var len = tfoot.length;
      var idx = -1;
      while (++idx < len) {
        var tok = tfoot[idx];
        define(tok, 'parent', tbody);
        tbody.nodes.push(tok);
      }
    }
  }

  ast.nodes = nodes;
  return ast;
}