tag <-function(tag) {new_function(exprs(... = ), #arguments of new functionexpr({ #body of the new function#classify tags as named components dots <-dots_partition(...)#focus on named components as the tags attribs <-html_attributes(dots$named)# otherwise, nested code children <-map_chr(dots$unnamed, escape)# paste brackets, tag names, and attributes together# then unquote user argumentshtml(paste0(!!paste0("<", tag), attribs, ">",paste(children, collapse =""),!!paste0("</", tag, ">") )) }),caller_env() #return the environment )}
Void tags
void_tag <-function(tag) {new_function(exprs(... = ), #allows for missing argumentsexpr({ dots <-dots_partition(...)# error checkif (length(dots$unnamed) >0) {abort(!!paste0("<", tag, "> must not have unnamed arguments")) } attribs <-html_attributes(dots$named)html(paste0(!!paste0("<", tag), attribs, " />")) }),caller_env() )}