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)

Markdown Extensions

# The following examples are short, so we set the HTML option 'fragment_only'

options(markdown.HTML.options = "fragment_only")

# no_intra_emphasis example
cat(markdownToHTML(text = "foo_bar_function", extensions = c()))

foobarfunction

cat(markdownToHTML(text = "foo_bar_function", extensions = c("no_intra_emphasis")))

foo_bar_function

# tables example (need 4 spaces at beginning of line here)
cat(markdownToHTML(text = "
    First Header  | Second Header
    ------------- | -------------
    Content Cell  | Content Cell
    Content Cell  | Content Cell
", extensions = c()))
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
# but not here
cat(markdownToHTML(text = "
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
", extensions = c("tables")))
First Header Second Header
Content Cell Content Cell
Content Cell Content Cell
# fenced_code example (need at least three leading ~ or `)
fenced_block <- function(text, x = "`", n = 3) {
  fence <- paste(rep(x, n), collapse = "")
  paste(fence, text, fence, sep = "")
}
cat(markdownToHTML(text = fenced_block("
preformatted text here without having to indent
first line.
"), extensions = c()))

preformatted text here without having to indent first line.

cat(markdownToHTML(text = fenced_block("
preformatted text here without having to indent
first line.
"), extensions = c("fenced_code")))
preformatted text here without having to indent
first line.
# autolink example
cat(markdownToHTML(text = "http://www.r-project.org/", extensions = c()))

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

cat(markdownToHTML(text = "http://www.r-project.org/", extensions = c("autolink")))

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

# strikethrough example
cat(markdownToHTML(text = "~~awesome~~", extensions = c()))

~~awesome~~

cat(markdownToHTML(text = "~~awesome~~", extensions = c("strikethrough")))

awesome

# lax_spacing
cat(markdownToHTML(text = "
Embedding html without surrounding with empty newline.
<div>_markdown_</div>
extra text.
", extensions = c("")))

Embedding html without surrounding with empty newline.

markdown
extra text.

cat(markdownToHTML(text = "
Embedding html without surrounding with empty newline.
<div>_markdown_</div>
extra text.
", extensions = c("lax_spacing")))

Embedding html without surrounding with empty newline.

_markdown_

extra text.

# space_headers example
cat(markdownToHTML(text = "#A Header\neven though there is no space between # and A",
                   extensions = c("")))

A Header

even though there is no space between # and A

cat(markdownToHTML(text = "#Not A Header\nbecause there is no space between # and N",
                   extensions = c("space_headers")))

#Not A Header because there is no space between # and N

# superscript example
cat(markdownToHTML(text = "2^10", extensions = c()))

2^10

cat(markdownToHTML(text = "2^10", extensions = c("superscript")))

210

HTML Options

# HTML OPTIONS

# The following examples are short, so we allways add the HTML option 'fragment_only'
tOpt <- "fragment_only"

# skip_html example
mkd = '<style></style><img src=""><a href="">Hello</a>'
cat(markdownToHTML(text = mkd, options = c(tOpt)))

Hello

cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_html")))

Hello

# skip_style example
cat(markdownToHTML(text = mkd, options = c(tOpt)))

Hello

cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_style")))

Hello

# skip_images example
cat(markdownToHTML(text = mkd, options = c(tOpt)))

Hello

cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_images")))

Hello

# skip_links example
cat(markdownToHTML(text = mkd, options = c(tOpt)))

Hello

cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_links")))

Hello

# safelink example
cat(markdownToHTML(text = '[foo](foo://bar "baz")', options = c(tOpt)))

foo

cat(markdownToHTML(text = '[foo](foo://bar "baz")', options = c(tOpt, "safelink")))

[foo](foo://bar “baz”)

# toc example
mkd <- paste(c("# Header 1", "p1", "## Header 2", "p2"), collapse = "\n")

cat(markdownToHTML(text = mkd, options = c(tOpt)))

Header 1

p1

Header 2

p2

cat(markdownToHTML(text = mkd, options = c(tOpt, "toc")))
Table of Contents

Header 1

p1

Header 2

p2

# hard_wrap example
cat(markdownToHTML(text = "foo\nbar\n", options = c(tOpt)))

foo bar

cat(markdownToHTML(text = "foo\nbar\n", options = c(tOpt, "hard_wrap")))

foo
bar

# use_xhtml example
cat(markdownToHTML(text = "foo\nbar\n", options = c(tOpt, "hard_wrap")))

foo
bar

cat(markdownToHTML(text = "foo\nbar\n", options = c(tOpt, "hard_wrap", "use_xhtml")))

foo
bar

# escape example
mkd = '<style></style><img src=""><a href="">Hello</a>'
cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_html")))

Hello

# overrides all 'skip_*' options
cat(markdownToHTML(text = mkd, options = c(tOpt, "skip_html", "escape")))

<style></style><img src=“”><a href=“”>Hello</a>

# smartypants example
cat(markdownToHTML(text = "1/2 (c)", options = c(tOpt)))

½ ©

cat(markdownToHTML(text = "1/2 (c)", options = c(tOpt, "smartypants")))

½ ©

cat(smartypants(text = "1/2 (c)\n"))

½ ©