tinkr
tinkr copied to clipboard
Add `replace()` method for yarn object
Now I wonder whether we still need to use replacement instead of adding. :thinking:
Originally posted by @maelle in https://github.com/ropensci/tinkr/issues/37#issuecomment-825418636
At the moment, we have an add_md()
method for the yarn object because adding nodes to the document was relatively straightforward process of
- convert markdown to nodes
- strip namespace from nodes
- add nodes to document
- copy document
We now have demonstrated processes of replacement as of #39, so adding a replace()
method should be as straightforward that takes in a node instead of a position like:
img_links <- xml2::xml_find_all(y$body, ".//md:image", ns = y$ns)
# transform image links to RMarkdown code chunks
y$replace(img_links, img_chunks)