How to use the unist-util-visit-parents.SKIP function in unist-util-visit-parents

To help you get started, we’ve selected a few unist-util-visit-parents 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 Prettyhtml / prettyhtml / packages / prettyhtml-formatter / index.js View on Github external
setNodeData(node, 'indentLevel', level - 1)

        // clear empty script, textarea, pre, style tags
        if (length) {
          const empty = hasOnlyEmptyTextChildren(node)
          const isEmbeddedContent = isElement(node, 'style') || isElement(node, 'script')
          if (empty) {
            // eslint-disable-next-line no-param-reassign
            node.children = []
          }
          if (usePrettier && !empty && isEmbeddedContent) {
            prettierEmbeddedContent(node, level, indent, prettierOpts)
          }
        }

        return visit.SKIP
      }

      let newline = false
      // we have to look in the future because we indent leading text
      // on a newline when a child text node contains a newline. If we wouldn't do this
      // the formatter could produce an unstable result because in the next step we could produce newlines.
      const collpased = peekCollpase(node, children)

      /**
       * Indent children
       */
      index = -1
      while (++index < length) {
        // eslint-disable-next-line no-shadow
        const child = children[index]
github syntax-tree / unist-util-visit / index.js View on Github external
'use strict'

module.exports = visit

var visitParents = require('unist-util-visit-parents')

var CONTINUE = visitParents.CONTINUE
var SKIP = visitParents.SKIP
var EXIT = visitParents.EXIT

visit.CONTINUE = CONTINUE
visit.SKIP = SKIP
visit.EXIT = EXIT

function visit(tree, test, visitor, reverse) {
  if (typeof test === 'function' && typeof visitor !== 'function') {
    reverse = visitor
    visitor = test
    test = null
  }

  visitParents(tree, test, overload, reverse)

  function overload(node, parents) {
github Prettyhtml / prettyhtml / packages / prettyhtml-formatter / index.js View on Github external
function setAttributeOnChildren(node, parents, attributeName, attributeValue) {
    const parent = parents[parents.length - 1]
    const nodeIndex = parent ? parent.children.indexOf(node) : null
    if (nodeIndex !== null) {
      for (let i = nodeIndex; i < parent.children.length; i++) {
        const child = parent.children[i]
        if (isElement(child)) {
          setNodeData(child, attributeName, attributeValue)
          return visit.SKIP
        }
      }
    }
  }

unist-util-visit-parents

unist utility to recursively walk over nodes, with ancestral information

MIT
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis