Skip to content
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

Clean up process for adding new nodes #12

Open
zkamvar opened this issue Sep 23, 2020 · 0 comments
Open

Clean up process for adding new nodes #12

zkamvar opened this issue Sep 23, 2020 · 0 comments

Comments

@zkamvar
Copy link
Contributor

zkamvar commented Sep 23, 2020

There are several places in the code where I add new nodes that need to be cleaned up, because there are so many different ways of doing it, but in reality, all I need to do is to add a node with the same namespace.

Path forward

Some relevant material is at ropensci/tinkr#24 is relevant material here, but an idea is that we have a general node generator that could look like:

make_node <- function(type, ..., ns = "http://commonmark.org/xml/1.0") glue::glue("<{type} {paste(..., collapse = ' ')}></{type}>")
p <- make_node("paragraph")
txt <- make_node("text")
xml2::xml_set_text(txt, "hello there")
xml2::xml_add_child(p, txt)

code <- make_node("code_block", "language='r'", "name='setup'", "eval=FALSE")
xml2::xml_set_text(code, "a <- 1:10\n")

Relevant places in the code

xml_new_paragraph <- function(text = "", ns, tag = TRUE) {

xml_slip_in <- function(body, to_insert, where = length(xml2::xml_children(body))) {

xml_list_chunk <- function(yaml, what, dovetail = TRUE) {

get_setup_chunk <- function(body) {

resolve_links <- function(txt, type) {

make_div <- function(what) {

clean_div_tags <- function(body) {

clean_fenced_divs <- function(body) {

zkamvar added a commit that referenced this issue Oct 14, 2020
 - xml_slip_in is no more!
 - prepare_yaml_packet replaces the xml_yaml function
 - move_yaml now uses proper element insertion with the correct
   namespace.
 - tests updated
 - pandoc fenced divs preferred

This will address #12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant