How to use unist-util-visit-parents - 10 common examples

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 tracespace / tracespace / packages / plotter / src / plot-tree / create-plot.ts View on Github external
let regionMode = false
  let interpolateMode: Parser.InterpolateModeType =
    format.filetype === Parser.GERBER ? Parser.LINE : null

  // arcs in drill files are always 180 degrees max
  let quadrantMode: Parser.QuadrantModeType = null

  const currentLayer: ImageLayer = {
    type: IMAGE_LAYER,
    size: BBox.empty(),
    children: [],
  }

  let currentPath: ImagePath | ImageRegion | null = null

  visit(image, visitNode)
  addCurrentPathToLayer()

  return {
    type: IMAGE,
    children: [currentLayer],
  }

  function addCurrentPathToLayer(): void {
    if (currentPath) {
      const pathSize = getPathBox(currentPath)
      currentLayer.size = BBox.add(currentLayer.size, pathSize)
      currentLayer.children.push(currentPath)
      currentPath = null
    }
  }
github jlevy / atom-flowmark / lib / remark-smart-word-wrap.js View on Github external
return ast => {
    // Mutate all pure text nodes to have normalized whitespace, so we don't
    // confuse ' ' and '\n' etc.
    normalizeTextNodes(ast);
    // Then walk all nodes.
    visitParents(ast, visitor);
  }
}
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 aliyun / alibabacloud-console-components / packages / gatsby-theme-console-doc / src / buildtime / remarkPlugins / linkInstructions / remarkPlugin.ts View on Github external
inst.instructionHandler({
                  node,
                  ancestors,
                  instructionParam: inst.instructionParam,
                  linkURL,
                  file,
                })
              ).then(() => res(true))
              // stop traversal because the instruction may change ast.
              // the ast may be **completly different** after this instruction's execution.
              // we will detect next instruction in the **next transform pass**.
              return visit.EXIT
            }
          }
        }
        return visit.CONTINUE
      })
      if (!foundLinkInstruction) res(false) // didn't find any instruction
github aliyun / alibabacloud-console-components / packages / gatsby-theme-console-doc / src / buildtime / remarkPlugins / linkInstructions / remarkPlugin.ts View on Github external
const inst = resolveLinkText(linkTextNode.value)
            if (inst) {
              foundLinkInstruction = true
              Promise.resolve(
                inst.instructionHandler({
                  node,
                  ancestors,
                  instructionParam: inst.instructionParam,
                  linkURL,
                  file,
                })
              ).then(() => res(true))
              // stop traversal because the instruction may change ast.
              // the ast may be **completly different** after this instruction's execution.
              // we will detect next instruction in the **next transform pass**.
              return visit.EXIT
            }
          }
        }
        return visit.CONTINUE
      })
      if (!foundLinkInstruction) res(false) // didn't find any instruction
github umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / jsx.ts View on Github external
export default () => (ast: Node) => {
  visitParents(ast, 'text', textVisitor);
  visit(ast, 'raw', rawVisitor);
};
github aliyun / alibabacloud-console-components / site / src / buildtime / legacyImportDemoInstruction / remarkPlugin.ts View on Github external
return (tree, file) => {
    tree.children.unshift({
      type: 'import',
      value: `import DemoRenderer__LegacyDemoInstructions from '@runtime/DemoRenderer'`,
    })
    visit(tree, 'paragraph', (node: mdast.Paragraph, ancestors) =>
      paragraphVistor(node, ancestors as mdast.Parent[], file)
    )
  }
}
github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
function mapImageTreeToSvg(node: ImageNode): SvgElement {
  switch (node.type) {
    case IMAGE: {
      let box = BBox.empty()
      unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
        box = BBox.add(box, layer.size)
      })
      const [xMin, yMin, width, height] = BBox.toViewBox(box)
      const props = {
        ...BASE_SVG_PROPS,
        width,
        height,
        viewBox: `${xMin} ${yMin} ${width} ${height}`,
      }
      return s('svg', props)
    }

    case IMAGE_LAYER: {
      const vbox = BBox.toViewBox(node.size)
      return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
github aliyun / alibabacloud-console-components / packages / gatsby-theme-console-doc / src / buildtime / remarkPlugins / linkInstructions / remarkPlugin.ts View on Github external
return new Promise(res => {
      let foundLinkInstruction = false
      visit(tree, 'link', (node, ancestors) => {
        const linkURL = node.url
        if (Array.isArray(node.children) && node.children.length === 1) {
          const linkTextNode = node.children[0]
          if (linkTextNode.type === 'text') {
            const inst = resolveLinkText(linkTextNode.value)
            if (inst) {
              foundLinkInstruction = true
              Promise.resolve(
                inst.instructionHandler({
                  node,
                  ancestors,
                  instructionParam: inst.instructionParam,
                  linkURL,
                  file,
                })
              ).then(() => res(true))
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) {

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