File: markdownExtensions.Rd

package info (click to toggle)
r-cran-markdown 1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 552 kB
  • sloc: ansic: 4,618; sh: 32; makefile: 7
file content (151 lines) | stat: -rw-r--r-- 4,535 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/renderMarkdown.R
\name{markdownExtensions}
\alias{markdownExtensions}
\title{Markdown extensions}
\usage{
markdownExtensions()
}
\value{
A \code{character} vector listing all available extensions.
}
\description{
\code{markdownExtensions} returns a character vector listing all the
extensions that are available in the \pkg{markdown} package.
}
\details{
They are all ON by default.

The \pkg{Sundown} library (upon which \pkg{markdown} is built) has optional
support for several extensions described below. To turn these on globally in
the \pkg{markdown} package, simply place some or all of them in a character
vector and assign to the global option \code{markdown.extensions} like so:

\code{options(markdown.extensions = markdownExtensions())}

To override the global option, pass the \code{extensions} as an argument to
one of the render functions, e.g.:

\code{markdownToHTML(..., extensions = c('no_intra_emphasis'))}

Description of all extensions:

\describe{

\item{\code{'no_intra_emphasis'}}{ skip markdown embedded in words.  }

\item{\code{'tables'}}{ create HTML tables (see Examples). }

\item{\code{'fenced_code'}}{ treat text as verbatim when surrounded with
begin and ending lines with three ~ or \emph{`} characters.  }

\item{\code{'autolink'}}{ create HTML links from urls and email addresses. }

\item{\code{'strikethrough'}}{ create strikethroughs by surrounding text with
~~.  }

\item{\code{'lax_spacing'}}{ allow HTML tags inside paragraphs without being
surrounded by newlines.  }

\item{\code{'space_headers'}}{ add a space between header hashes and the
header itself.  }

\item{\code{'superscript'}}{ translate ^ and subsequent text into HTML
superscript. }

\item{\code{'latex_math'}}{ transforms all math equations into syntactically
correct MathJax equations.  }

}

See the EXAMPLES section to see the output of each extension turned on or
off.
}
\examples{
# List all available extensions:
markdownExtensions()

# To turn on all markdown extensions globally:
options(markdown.extensions = markdownExtensions())

# To turn off all markdown extensions globally:
options(markdown.extensions = NULL)

# 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()))
cat(markdownToHTML(text = "foo_bar_function", extensions = c("no_intra_emphasis")))

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

# but not here
cat(markdownToHTML(text = "
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
", 
    extensions = c("tables")))

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

cat(markdownToHTML(text = fenced_block("
preformatted text here without having to indent
first line.
"), 
    extensions = c("fenced_code")))

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

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

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

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

# superscript example
cat(markdownToHTML(text = "2^10", extensions = c()))
cat(markdownToHTML(text = "2^10", extensions = c("superscript")))
}
\seealso{
\link{markdownHTMLOptions}
}