Closed weituotian closed 4 years ago
Hi! 👋
Trees are a JSON structure. That means that it’s arrays and objects, and you can use standard javascript functions such as .push
to add something or children[index] = newNode
.
More info on traversing the tree is described here: https://github.com/unifiedjs/unifiedjs.github.io/blob/src/doc/learn/tree-traversal.md.
It’s a good idea to look at the hundreds of utilities and plugins that exist for inspiration!
I believe this question is now answered, so I’ll close it. Feel free to ask more questions, or continue here. However, Spectrum is the best place for questions!
@wooorm thanks!! but i worry about how to modify the position attr of a node structure
If you are adding a new node, or replacing an existing node with a new node, it is suggested to not add positional info to them. Positional information references a place in an original source document, so if the things wasn’t in that document, it shouldn’t have positional information!
Subject of the feature
insert a node or remove a node in ast tree
Problem
could not find some method for Node to modify its text, its position.
Expected behaviour
add some api for Node
Alternatives
jquery can modify the dom ele positions and its attrs