-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prevent to_md() from clobbering document (and friends!) #15
Conversation
This serves as a followup to ropensci#14
- to_xml only processes info of blocks that have curly braces - transform_code_blocks only looks for the code blocks with a language attribute (avoids ```{NA} code chunks) - example blocks have been added to Rmarkdown example - tests incorporated
The to_md() function would clobber the original xml document because all of the functions on xml documents are pass by reference instead of the trusty ol' R pass-by-value :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a ton!!
#' # file.edit("newmd.md") | ||
#' file.remove(newmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better! should I submit this to CRAN one day? If I do you'll have to become an author.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have on CRAN at some point, but I might like to give #9 a shot first 😉
code_blocks <- xml %>% | ||
xml2::xml_find_all(xpath = './/d1:code_block', | ||
xml2::xml_find_all(xpath = './/d1:code_block[@language]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so much more elegant! ✨
Would it be fine to add you as an author before merging? If so, please go ahead and add your metadata. |
Description
I've done a couple of things here (I apologize for shoving too many things in a single PR, but I figured they were all roughly related):
sourcepos
option added if read in with sourcepos = TRUE (whoops 😳)to_xml()
to only post-process code blocks that have a language attribute to allow bare or unevaluated code fences.Example
Created on 2020-05-28 by the reprex package (v0.3.0)