ropensci / tinkr

Convert (R)Markdown files to XML, edit them, write them back as (R)Markdown
https://docs.ropensci.org/tinkr
GNU General Public License v3.0
57 stars 3 forks source link

Add helper functions for adding/extracting features #28

Open zkamvar opened 4 years ago

zkamvar commented 4 years ago

Is it worthwhile to add helper functions for adding or extracting nodes? There is an issue around namespaces, which can be tricky. Things I think could be on the docket to add:

The namespace thing is tricky, should your PR actually add a helper function for adding childs (and siblings and parents?)? The arguments would be everything but not the namespace, that tinkr would set. The function would also check the text ends with a newline, if there's text.

I think adding helper functions for these situations would be quite nice. The only thing is that the code block example is one of the simplest situations because you only need the code block and the text that goes inside. It gets more complex with almost any other element.

One avenue we might explore is having a helper function that inserts user markdown as nodes by passing it through commonmark::markdown_xml() and then taking the children of that new document. That's was one of the strategies I found to work with dealing with list elements in {pegboard}

Originally posted by @zkamvar in https://github.com/ropensci/tinkr/pull/24#issuecomment-699036027

zkamvar commented 4 years ago

Note that this issue ties closely with #27

zkamvar commented 4 years ago

After getting lost in namespace weeds a bit, it appears that this feature is definitely needed because there is no way to cleanly add nodes into the default namespace: https://community.rstudio.com/t/adding-nodes-in-xml2-how-to-avoid-duplicate-default-namespaces/84870/2

maelle commented 3 years ago

now that one can add Markdown, is this still needed?