tinkr icon indicating copy to clipboard operation
tinkr copied to clipboard

Add `replace()` method for yarn object

Open zkamvar opened this issue 3 years ago • 1 comments

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

  1. convert markdown to nodes
  2. strip namespace from nodes
  3. add nodes to document
  4. 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)

zkamvar avatar May 11 '21 17:05 zkamvar