-
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
only set info attribute for language blocks #24
Conversation
This is on the way to addressing ropensci#23, but doesn't fix it :(
|
||
> NOTE: Inserting new code MUST have a newline character at the end of the |
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.
why, btw?
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.
I'm not sure! I think it has something to do with a fencepost problem in the stylesheet because the last line of code is accessible before it hits xslt::xml_xslt()
. I think it may be worthwhile to open an issue to figure out what's going on, but probably not too high priority IMO.
Co-authored-by: Maëlle Salmon <maelle.salmon@yahoo.se>
Not sure if helpful but I used your edit of path <- system.file("extdata", "example2.Rmd", package = "tinkr")
yaml_xml_list <- tinkr::to_xml(path)
# Add chunk into document
xml2::xml_add_child(yaml_xml_list$body,
"code_block",
"this is a new chunk from {tinkr}\n",
language='r', name='xml-block',
xmlns=xml2::xml_ns(yaml_xml_list$body),
.where = 1L)
tou <- tempfile(fileext = ".Rmd")
tinkr::to_md(yaml_xml_list, tou)
file.edit(tou) I was wondering whether it was more natural to add a chunk this way? I.e. not creating a node, but instead using the "..." of 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 saw you're into R6 and I wonder whether that's the route we should go in tinkr too instead of using a list? |
YES! 💯 I think the method you proposed is a MUCH better way of doing things. I admit that I'm always a bit perplexed by the {xml2} documentation, and never really understood what was going on with the
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
I'm ambivalent about this. I've found it to be quite useful for my own tasks and it reinforces the concept that {xml2} objects work by side-effect, but on the other hand, it may not be strictly necessary. I guess it depends on what the perceived audience will do with it. 🤷 |
Well for now the perceived audience is you and me 🤣 |
This may not necessarily be the case AND I just realized that this could tie into #20 because if the intention is to allow users to insert any random markdown, then it can be inserted into a text node and it would come out in the rendered document as markdown. The only things we would need to do is to add a tag to that text that would prevent it from be escaped on its way out. I used this strategy in {pegboard}. |
@maelle, do you think this can be merged? This bugfix would really help me refactor {pegboard}. |
Now that <SNAP! voice> I've got the power </SNAP! voice> to merge PRs, I will do this self-merge since I have addressed @maelle's requests. |
This will fix #23 via https://github.com/ropenscilabs/tinkr/pull/24/files#diff-cf43f9aae06899fecb008822d7d986c4R113, which sets the "info" attribute instead of resetting ALL attributes. The only potential drawback is if any of the chunk-derived attributes interact with the stylesheet, but I can't see any pathways so far.
I've also added some documentation in the README about the process for adding new elements (which really should be a vignette on its own):