-
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
create append_md and prepend_md methods #119
base: main
Are you sure you want to change the base?
Conversation
I just tried this in a real-world situation, and 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.
🚀
@@ -2,6 +2,8 @@ | |||
|
|||
## NEW FEATURES | |||
|
|||
* `yarn$append_md()` and `yarn$prepend_md()` methods allow you to add new |
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.
nice! curious to hear what your use case was?
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 wanted to try to modify the installation section of hubverse packages to have "On the R Universe" and "Development" subsections, and this the previous method of needing to know the exact position of the node in the document was frustrating.
|
||
shove_nodes_in <- function(body, new, nodes, where = "after", space = TRUE) { | ||
if (inherits(nodes, "character")) { | ||
nodes <- xml2::xml_find_all(body, nodes, ns = md_ns()) |
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.
error if none found?
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.
because the error that's right after might be too mysterious
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.
That's a good point. I'll try it out.
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.
oh yeah, especially given that there is xml_missing
copy_xml(body) | ||
} | ||
|
||
shove_nodes_in <- function(body, new, nodes, where = "after", space = TRUE) { |
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.
do you want to start using devtag for documenting internal functions? https://github.com/moodymudskipper/devtag
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.
Ohhh I think I should!
class = "insert-md-body" | ||
) | ||
} | ||
return(add_nodes_to_nodes(new, old = nodes, where = where, space = space)) |
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 an explicit return()
?
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 think I was burned about this with JavaScript and vowed to always use the explicit return, but I know that it's against the standard R style.
#' parameter. | ||
#' @param space if `TRUE`, inline nodes will have a space inserted before | ||
#' they are appended. | ||
#' @details this is similar to the `add_md()` method except that it can do |
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.
should there be a @family
tag in both manual pages?
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.
Oh yes!
Not sure why it took me THREE MONTHS to have a look 🙈 |
It's been a busy three months! |
And another bug for prepending inline nodes. tst <- tinkr::yarn$new(textConnection("how are you?"))
tst$prepend_md("_hello_?", ".//md:text")
# should be "*hello*? how are you?"
tst$show()
#> *hello *?how are you? Created on 2024-11-05 with reprex v2.1.1 |
This creates two new methods for
yarn
objects:$append_md()
and$prepend_md()
which allows users to use XPath or nodesto choose where to insert markdown.
With
prepend_md()
, you can add elements you forgot such as table captions:With
append_md()
you can add more context, such as adding a note after allthe headings
We can also make the heading text more exciting with exclamation points!
Created on 2024-06-21 with reprex v2.1.0
One huge benefit of this is that markdown can be inserted on a broad spectrum.