HTML Output from Markdown Examples

This vignette shows how the output looks like in HTML from the other vignette markdown-examples.Rmd, in which the literal HTML code was shown.

library(markdown)

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

cat(mark(mkd, options = "+number_sections"))

1. Header 1

p1

1.1 Header 2

p2

cat(mark(mkd, options = "+number_sections+toc"))

1. Header 1

p1

1.1 Header 2

p2

# hard_wrap example
cat(mark("foo\nbar\n"))

foo bar

cat(mark("foo\nbar\n", options = "hard_wrap"))

foo
bar

# 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))

$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, options = "-latex_math"))

$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}

# tables example (need 4 spaces at beginning of line here)
cat(mark("
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
"))
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'))

First Header | Second Header ———–– | ———–– Content Cell | Content Cell Content Cell | Content Cell

# autolink example
cat(mark("https://www.r-project.org/"))

https://www.r-project.org/

cat(mark("https://www.r-project.org/", options = "-autolink"))

https://www.r-project.org/

# strikethrough example
cat(mark("~~awesome~~"))

awesome

cat(mark("~~awesome~~", options = "-strikethrough"))

~~awesome~~

# superscript and subscript examples
cat(mark("210"))

210

cat(mark("210", options = "-superscript"))

210

cat(mark("H2O"))

H2O

cat(mark("H2O", options = "-subscript"))

H2O

# code blocks
cat(mark('```r\n1 + 1;\n```'))
1 + 1;
cat(mark('```{.r}\n1 + 1;\n```'))
1 + 1;
cat(mark('```{.r .js}\n1 + 1;\n```'))
1 + 1;
cat(mark('```{.r .js #foo}\n1 + 1;\n```'))
1 + 1;
cat(mark('```{.r .js #foo style="color:red;"}\n1 + 1;\n```'))
1 + 1;
cat(mark('````\n```{r, echo=TRUE}\n1 + 1;\n```\n````'))
```{r, echo=TRUE}
1 + 1;
```
# raw blocks
cat(mark('```{=html}\n<p>raw HTML</p>\n```'))

raw HTML

cat(mark('```{=latex}\n<p>raw HTML</p>\n```'))

# skip_html tags
mkd = '<style>a {}</style><script type="text/javascript">console.log("No!");</script>\n[Hello](#)'
cat(mark(mkd))

Hello

# TODO: wait for https://github.com/r-lib/commonmark/issues/15 to be fixed
# cat(mark(mkd, options = "tagfilter"))
# smartypants example
cat(mark("&frac12; &copy;"))

½ ©

mkd <- paste(names(markdown:::pants), collapse = ' ')
cat(mark(mkd))

½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ⅐ ⅑ ⅒ © ® ™