Skip to content

Utilities for creation & injection of AST nodes #38

Answered by ChristianMurphy
cdaringe asked this question in Q&A
Discussion options

You must be logged in to vote

Personally I tend to use unist-util-visit and unist-util-visit-parents the most, in both cases, mutating a node will modify the original AST.
For particularly complex node access, I may use unist-util-select to be able to leverage CSS-like selectors.

Another approach, specifically for building nodes is to use JSX syntax.
Which is built into xastscript and hastscript (in a yet to be released version). it can also be applied to other AST builders.

I was hoping for something like insertAfter(root, target, u(...myNewNode)), akin to DOM APIs

More DOM style APIs could be good contributions to unist/syntax-tree! Are you interested in creating some?
Some related ideas could include building out…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@cdaringe
Comment options

@ChristianMurphy
Comment options

Answer selected by ChristianMurphy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants