Save a file or URL to a Markdown file
save_to_md.RdSaves an HTML file, URL, Word document, or other pandoc-supported input to a Markdown file. Conversion is performed using Pandoc.
Usage
save_to_md(
input,
output,
md_format = md_format_default,
wrap = Inf,
args_to_deflist = FALSE
)Arguments
- input
(Scalar character)
Path to a local file or a URL (http://orhttps://). Common inputs include.htmlfiles,.docxfiles, and URLs. Any format supported by Pandoc is accepted.- output
(Scalar character)
File path where the result will be written. The extension must be.md.- md_format
(Scalar character:
md_format_default)
Pandoc output format string used for Markdown conversion. See Pandoc manual for available formats and extensions.- wrap
(Scalar integer:
Inf;[1, Inf])
Column width for word wrapping in Markdown output.Infdisables wrapping.- args_to_deflist
(Scalar logical:
FALSE)
IfTRUE, converts argument tables in the HTML to definition lists before Markdown conversion. Only applies wheninputis an HTML file or URL.
Examples
#----------------------------------------------------------------------------
# save_to_md() example
#----------------------------------------------------------------------------
library(bkmisc)
# Save a local HTML help page to markdown
html_in <- tempfile(fileext = ".html")
tools::Rd2HTML(
tools::Rd_db("base")[["mean.Rd"]],
out = html_in,
package = "base"
)
md_out <- tempfile(fileext = ".md")
save_to_md(html_in, md_out)
readLines(md_out) |> head(20)
#> [1] " ------------- -----------------"
#> [2] " mean {base} R Documentation"
#> [3] " ------------- -----------------"
#> [4] ""
#> [5] "## Arithmetic Mean"
#> [6] ""
#> [7] "### Description"
#> [8] ""
#> [9] "Generic function for the (trimmed) arithmetic mean."
#> [10] ""
#> [11] "### Usage"
#> [12] ""
#> [13] "``` R"
#> [14] "mean(x, ...)"
#> [15] ""
#> [16] "## Default S3 method:"
#> [17] "mean(x, trim = 0, na.rm = FALSE, ...)"
#> [18] "```"
#> [19] ""
#> [20] "### Arguments"