to_md | R Documentation |
Write front-matter (YAML, TOML or JSON) and XML back to disk as (R)Markdown
to_md(
frontmatter_xml_list,
path = NULL,
stylesheet_path = stylesheet(),
yaml_xml_list = deprecated()
)
to_md_vec(nodelist, stylesheet_path = stylesheet())
frontmatter_xml_list |
result from a call to |
path |
path of the new file. Defaults to |
stylesheet_path |
path to the XSL stylesheet |
yaml_xml_list |
|
nodelist |
an object of |
The stylesheet you use will decide whether lists
are built using "*" or "-" for instance. If you're keen to
keep your own Markdown style when using to_md()
after
to_xml()
, you can tweak the XSL stylesheet a bit and provide
the path to your XSL stylesheet as argument.
to_md()
: \[character\]
the converted document, invisibly as a character vector containing two elements: the frontmatter list and the markdown body.
to_md_vec()
: \[character\]
the markdown representation of each node.
path <- system.file("extdata", "example1.md", package = "tinkr")
frontmatter_xml_list <- to_xml(path)
names(frontmatter_xml_list)
# extract the level 3 headers from the body
headers3 <- xml2::xml_find_all(
frontmatter_xml_list$body,
xpath = './/md:heading[@level="3"]',
ns = md_ns()
)
# show the headers
print(h3 <- to_md_vec(headers3))
# transform level 3 headers into level 1 headers
# NOTE: these nodes are still associated with the document and this is done
# in place.
xml2::xml_set_attr(headers3, "level", 1)
# preview the new headers
print(h1 <- to_md_vec(headers3))
# save back and have a look
newmd <- tempfile("newmd", fileext = ".md")
res <- to_md(frontmatter_xml_list, newmd)
# show that it works
regmatches(res[[2]], gregexpr(h1[1], res[[2]], fixed = TRUE))
# file.edit("newmd.md")
file.remove(newmd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.