# List all available options
markdown::markdown_options()
# Turn on/off some options globally for HTML output
options(markdown.html.options = '+toc-smartypants-standalone')
library(markdown)
# toc example
mkd <- c("# Header 1", "p1", "## Header 2", "p2")
cat(mark(mkd))
cat(mark(mkd, options = "toc"))
# hard_wrap example
cat(mark("foo\nbar\n"))
cat(mark("foo\nbar\n", options = "hard_wrap"))
# latex math example
mkd <- c(
"`$x$` is inline math $x$!", "", "Display style:", "", "$$x + y$$", "",
"\\begin{eqnarray}
a^{2}+b^{2} & = & c^{2}\\\\
\\sin^{2}(x)+\\cos^{2}(x) & = & 1
\\end{eqnarray}"
)
cat(mark(mkd))
cat(mark(mkd, options = "-latex_math"))
# smartypants example
cat(mark("1/2 (c)"))
cat(mark("1/2 (c)", options = "-smartypants"))
mkd <- names(markdown:::pants)
mkd <- paste(c(mkd, paste0('`', mkd, '`')), collapse = ' ')
cat(mark(mkd))
cat(mark(mkd, options = "-smartypants"))
cat(smartypants("1/2 (c)\n"))
# tables example (need 4 spaces at beginning of line here)
cat(mark("
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
"))
# but not here
cat(mark("
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
", options = '-table'))
# autolink example
cat(mark("https://www.r-project.org/"))
cat(mark("https://www.r-project.org/", options = "-autolink"))
# strikethrough example
cat(mark("~~awesome~~"))
cat(mark("~~awesome~~", options = "-strikethrough"))
# superscript and subscript examples
cat(mark("2^10^"))
cat(mark("2^10^", options = "-superscript"))
cat(mark("H~2~O"))
cat(mark("H~2~O", options = "-subscript"))
# skip_html tags
mkd = '\n[Hello](#)'
cat(mark(mkd))
# TODO: wait for https://github.com/r-lib/commonmark/issues/15 to be fixed
# cat(mark(mkd, options = "tagfilter"))
Run the code above in your browser using DataLab