-
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
Use R6 representation #33
Conversation
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.
This is awesome, thank you! I left a few comments.
Another question that I have is how this should be documented in the README. What approach would we recommend first, R6 or not? In any case at the very top of the README where there's a list of use cases you could add "add an arbitrary new Markdown element like a table".
Co-authored-by: Maëlle Salmon <maelle.salmon@yahoo.se>
I think we can recommend the R6 approach first since it's arguably more straightforward given that we are defining the namespace prefix in the object. So the first block would turn into this: # From Markdown to XML
path <- system.file("extdata", "example1.md", package = "tinkr")
y <- yarn$new(path)
library("magrittr")
# transform level 3 headers into level 1 headers
body <- y$body
ns <- y$ns
body %>%
xml2::xml_find_all(xpath = './/md:heading[@level="3"]', ns) -> headers3
xml2::xml_set_attr(headers3, "level", 1)
y$body <- body
# Back to Markdown
y$write("newmd.md")
file.edit("newmd") |
- stylesheet is now checked for validity - path is now an optional argument in `to_md()` - to_md() now returns the rendered markdown, invisibly - several parts of to_md() were split off into new functions
Still to do:
|
Reg the example I think adding R6 is fine but we might lose some folks if using "->" for assignment 😉 I wonder whether we should add a short list of things that people might enjoy learning about for maximal enjoyment of tinkr
|
come to think of it, for this particular example, we don't even need to use any assignment: y$body %>%
xml2::xml_find_all(xpath = './/md:heading[@level="3"]', y$ns) %>%
xml2::xml_set_attr("level", 1)
y$write("newmd.md")
YES! Your original link to the XPath page really helped me learn, so I think these extras would also help. It may also be worthwhile thinking about writing up some documentation about how the XSLT stylesheet in {tinkr} works broadly (e.g. that it uses the commonmark namespace and imports the commonmark stylesheet). I also realized that it's possible to manipulate a stylesheet with {xml2} so that users can change things like bullet point shape |
We have checks in place that detect for evaluated chunks, so skipping based on file name is not necessary. Moreover, this will allow file connections to be used.
I opened a few issues |
This is very strange.... I'm able to get the tests to pass on my machine, even with a clean version of the git repo. |
I think this can be merged that the basic elements of the R6 class have been addressed. I think any other modifications should be new PRs. It's also worthwhile to note that this merge will not change any existing workflows. |
I've added an R6 class object with four methods: new, write, reset, and add_md.
I've also added test fixtures and snapshot tests (which are super fun!) (I also may have been on the rOpenSci allcaps when I was writing some of the tests...)
this PR will fix #25, fix #27, and address #28