Skip to content

How do I change the value of a node property and save the new tree #201

Discussion options

You must be logged in to vote

Welcome @mirhamasala! 👋
You're on the right track, and from a cursory glance I think the code may already work?
Visit allows for changes to be made directly to the tree in place.
I tried it in the rehype sandbox wrapping it as a plugin: https://codesandbox.io/s/zealous-matan-nf9gec?file=/src/index.js and it appeared to work.

A couple minor suggestions which may further improve the code (both are incorporated in the sandbox above).

  1. Consider applying the changes from inside a unified/rehype plugin, this allows for updates to content to be more easily chained.
  2. Consider using the test option from unist-util-visit to more quickly filter the tree to find the image elements. Something like { ty…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mirhamasala
Comment options

You must be logged in to vote
0 replies
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