This vignette shows some examples for different Markdown rendering options.

library(markdown)

# toc example
mkd <- c("# Header 1", "p1", "## Header 2", "p2")

cat(mark(mkd))
<h1>Header 1</h1>
<p>p1</p>
<h2>Header 2</h2>
<p>p2</p>
cat(mark(mkd, options = "toc"))
<div id="TOC">
<ul>
<li>Header 1
<ul>
<li>Header 2</li>
</ul>
</li>
</ul>
</div>
<h1>Header 1</h1>
<p>p1</p>
<h2>Header 2</h2>
<p>p2</p>
# hard_wrap example
cat(mark("foo\nbar\n"))
<p>foo
bar</p>
cat(mark("foo\nbar\n", options = "hard_wrap"))
<p>foo<br />
bar</p>
# 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))
<p><code>$x$</code> is inline math \(x\)!</p>
<p>Display style:</p>
<p>$$x + y$$</p>
<p>\begin{eqnarray} a^{2}+b^{2} &amp; = &amp; c^{2}\\ \sin^{2}(x)+\cos^{2}(x) &amp; = &amp; 1 \end{eqnarray}</p>
cat(mark(mkd, options = "-latex_math"))
<p><code>$x$</code> is inline math $x$!</p>
<p>Display style:</p>
<p>$$x + y$$</p>
<p>\begin{eqnarray}
a^{2}+b^{2} &amp; = &amp; c^{2}\
\sin^{2}(x)+\cos^{2}(x) &amp; = &amp; 1
\end{eqnarray}</p>
# smartypants example
cat(mark("1/2 (c)"))
<p>½ ©</p>
cat(mark("1/2 (c)", options = "-smartypants"))
<p>1/2 (c)</p>
mkd <- names(markdown:::pants)
mkd <- paste(c(mkd, paste0('`', mkd, '`')), collapse = ' ')
cat(mark(mkd))
<p>½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ⅐ ⅑ ⅒ © ® ™ <code>1/2</code> <code>1/3</code> <code>2/3</code> <code>1/4</code> <code>3/4</code> <code>1/5</code> <code>2/5</code> <code>3/5</code> <code>4/5</code> <code>1/6</code> <code>5/6</code> <code>1/8</code> <code>3/8</code> <code>5/8</code> <code>7/8</code> <code>1/7</code> <code>1/9</code> <code>1/10</code> <code>(c)</code> <code>(r)</code> <code>(tm)</code></p>
cat(mark(mkd, options = "-smartypants"))
<p>1/2 1/3 2/3 1/4 3/4 1/5 2/5 3/5 4/5 1/6 5/6 1/8 3/8 5/8 7/8 1/7 1/9 1/10 (c) (r) (tm) <code>1/2</code> <code>1/3</code> <code>2/3</code> <code>1/4</code> <code>3/4</code> <code>1/5</code> <code>2/5</code> <code>3/5</code> <code>4/5</code> <code>1/6</code> <code>5/6</code> <code>1/8</code> <code>3/8</code> <code>5/8</code> <code>7/8</code> <code>1/7</code> <code>1/9</code> <code>1/10</code> <code>(c)</code> <code>(r)</code> <code>(tm)</code></p>
cat(smartypants("1/2 (c)\n"))
&frac12; &copy; 
# tables example (need 4 spaces at beginning of line here)
cat(mark("
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
"))
<table>
<thead>
<tr>
<th>First Header</th>
<th>Second Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content Cell</td>
<td>Content Cell</td>
</tr>
<tr>
<td>Content Cell</td>
<td>Content Cell</td>
</tr>
</tbody>
</table>
# but not here
cat(mark("
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
", options = '-table'))
<p>First Header  | Second Header
———–– | ———––
Content Cell  | Content Cell
Content Cell  | Content Cell</p>
# autolink example
cat(mark("https://www.r-project.org/"))
<p><a href="https://www.r-project.org/">https://www.r-project.org/</a></p>
cat(mark("https://www.r-project.org/", options = "-autolink"))
<p>https://www.r-project.org/</p>
# strikethrough example
cat(mark("~~awesome~~"))
<p><del>awesome</del></p>
cat(mark("~~awesome~~", options = "-strikethrough"))
<p>~~awesome~~</p>
# superscript and subscript examples
cat(mark("2^10^"))
<p>2<sup>10</sup></p>
cat(mark("2^10^", options = "-superscript"))
<p>2^10^</p>
cat(mark("H~2~O"))
<p>H<sub>2</sub>O</p>
cat(mark("H~2~O", options = "-subscript"))
<p>H~2~O</p>
# skip_html tags
mkd = '<style>a {}</style><script type="text/javascript">console.log("No!");</script>\n[Hello](#)'
cat(mark(mkd))
<style>a {}</style><script type="text/javascript">console.log("No!");</script>
<p><a href="#">Hello</a></p>
# TODO: wait for https://github.com/r-lib/commonmark/issues/15 to be fixed
# cat(mark(mkd, options = "tagfilter"))