Skip to content

Commit

Permalink
add dev comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zkamvar committed Nov 5, 2024
1 parent 798f62b commit 8cd7583
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
^inst/scripts/samples.R
^inst/extdata/bigsample.*$
^inst/extdata/xml_table.xml$
^man/add_md\.Rd$
^man/add_nodes_to_body\.Rd$
^man/insert_md\.Rd$
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Suggests:
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "devtag::dev_roclet"))
RoxygenNote: 7.3.2.9000
VignetteBuilder: knitr
Config/Needs/build: moodymudskipper/devtag
22 changes: 21 additions & 1 deletion R/add_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
#' @keywords internal
#'
#' @return a copy of the XML object with the markdown inserted.
#' @dev
add_md <- function(body, md, where = 0L) {
new <- md_to_xml(md)
add_nodes_to_body(body, new, where)
copy_xml(body)
}

# Add children to a specific location in the full document.
#' Add children to a specific location in the full document.
#'
#' @inheritParams add_md
#' @param nodes an object of `xml_node` or list of nodes
#' @return a copy of the XML object with nodes inserted
#' @dev
add_nodes_to_body <- function(body, nodes, where = 0L) {
if (inherits(nodes, "xml_node")) {
xml2::xml_add_child(body, nodes, .where = where)
Expand All @@ -21,6 +27,20 @@ add_nodes_to_body <- function(body, nodes, where = 0L) {
}
}


#' Insert markdown before or after a set of nodes
#'
#' @inheritParams add_md
#' @param md markdown text to insert
#' @param nodes a character vector of an XPath expression OR an `xml_node` or
#' `xml_nodeset` object.
#' @param space when `TRUE` (default) inline nodes have a single space appended
#' or prepended to avoid the added markdown abutting text.
#' @return a copy of the XML object with the translated markdown inserted
#'
#' @note The markdown content must be of the same type as the XML nodes, either
#' inline or block content.
#' @dev
insert_md <- function(body, md, nodes, where = "after", space = TRUE) {
new <- md_to_xml(md)
shove_nodes_in(body, new, nodes = nodes, where = where, space = space)
Expand Down
1 change: 1 addition & 0 deletions man/add_md.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/add_nodes_to_body.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/insert_md.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/isolate_nodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/provision_isolation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/yarn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cd7583

Please sign in to comment.