A Swift library set for parsing, inspecting, generating and transforming Swift source code as a source-accurate syntax tree.
syntax-tree/unist-util-visit
A unist utility for walking and visiting nodes in syntax trees such as Markdown ASTs, with a test filter and enter/exit visitors.
- Stars
- 359
- Forks
- 23
- Open issues
- 0
- Last commit
- 14 days ago
What is it?
unist-util-visit walks through a unist-based syntax tree, such as the MDAST trees produced by mdast-util-from-markdown, and calls a visitor function on each node. You can pass a test to restrict visits to matching nodes, using the same test format as unist-util-is, such as a node type string.
Visitors receive the node, its index in the parent, and the parent itself. Each visitor can return CONTINUE, EXIT to stop traversal, or SKIP to skip a node's children, and a separate exit visitor can run after a node's children are processed. The package is ESM only, targets Node.js 16+, and is also usable from Deno and browsers via esm.sh.
If you need the full chain of ancestors for each node, the sibling package unist-util-visit-parents provides that; this package works the same way but exposes parent and index instead.
Key features
- 01Visits every node in a unist tree, optionally filtered by a test such as a node type.
- 02Visitors receive the node, its index, and its parent.
- 03Return CONTINUE, EXIT, or SKIP to control traversal.
- 04Supports separate enter and exit visitors.
- 05Works in Node.js, Deno, and browsers via esm.sh.
Use cases
- Finding and transforming specific Markdown nodes, such as all text or code nodes, in a remark or unified plugin.
- Collecting information from a syntax tree during a build step.
- Building custom linters or transformers on top of unist-compatible parsers.
Quick start
- 1
Install the package with npm (Node.js 16+)
npm install unist-util-visit - 2
Import visit and walk a syntax tree, such as one produced by fromMarkdown
Things to know
- This package is ESM only, so it cannot be loaded with require() in CommonJS projects.
- It is a low-level tree-walking utility for unist trees and needs a parser such as mdast-util-from-markdown to produce input.
In collections
Topics
FAQ
- What is unist-util-visit?
- A unist utility for walking and visiting nodes in syntax trees such as Markdown ASTs, with a test filter and enter/exit visitors. unist-util-visit walks through a unist-based syntax tree, such as the MDAST trees produced by mdast-util-from-markdown, and calls a visitor function on each node. You can pass a test to restrict visits to matching nodes, using the same test format as unist-util-is, such as a node type string.
- Is unist-util-visit free to use? What license does it have?
- unist-util-visit is open source under the MIT license. Check the license terms before using it in commercial products.
- Is unist-util-visit still maintained?
- Actively maintained. The last commit to unist-util-visit was on Oct 24, 2026.
- What can I use unist-util-visit for?
- Finding and transforming specific Markdown nodes, such as all text or code nodes, in a remark or unified plugin. Collecting information from a syntax tree during a build step. Building custom linters or transformers on top of unist-compatible parsers.
- How do I install unist-util-visit?
- Install the package with npm (Node.js 16+): npm install unist-util-visit Import visit and walk a syntax tree, such as one produced by fromMarkdown
- Where can I get unist-util-visit?
- The source code and installation instructions are on GitHub: https://github.com/syntax-tree/unist-util-visit
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python parser that builds syntax trees with error recovery and round-trip source preservation across Python versions.
MDX is a format for writing JSX components inside Markdown documents, with compilers for bundlers and React, Preact, and Vue.
An opinionated code formatter that re-prints JavaScript, TypeScript, CSS, HTML, Markdown, YAML and more to a consistent style.
A rule-based linter and auto-fixer for Chinese Markdown, built on an AST, with CLI, Prettier, ESLint and VS Code integrations and a programmatic API.
An incremental parser generator and parsing library that builds concrete syntax trees and updates them as source files are edited.