0.1 Test Markdown options

library(litedown)
# toc example
mkd <- c('# Header 1', 'p1', '## Header 2', 'p2')

mark(mkd, options = '+number_sections')
<div id="TOC">
<ul class="numbered">
<li><a href="#chp:header-1"><span class="section-number main-number">1</span> Header 1</a>
<ul>
<li><a href="#sec:header-2"><span class="section-number">1.1</span> Header 2</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="chp:header-1"><span class="section-number main-number">1</span> Header 1</h1>
<p>p1</p>
<h2 id="sec:header-2"><span class="section-number">1.1</span> Header 2</h2>
<p>p2</p>
mark(mkd, options = '+number_sections+toc')
<div id="TOC">
<ul class="numbered">
<li><a href="#chp:header-1"><span class="section-number main-number">1</span> Header 1</a>
<ul>
<li><a href="#sec:header-2"><span class="section-number">1.1</span> Header 2</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="chp:header-1"><span class="section-number main-number">1</span> Header 1</h1>
<p>p1</p>
<h2 id="sec:header-2"><span class="section-number">1.1</span> Header 2</h2>
<p>p2</p>
# hard_wrap example
mark('foo\nbar\n')
<p>foo
bar</p>
mark('foo\nbar\n', options = '+hardbreaks')
<p>foo<br />
bar</p>
# latex math example
mkd <- c(
  '`$x$` is inline math $x$!', '', 'Display style:', '', '$$x + y$$', '',
  '\\begin{align}
a^{2}+b^{2} & = c^{2}\\\\
\\sin^{2}(x)+\\cos^{2}(x) & = 1
\\end{align}'
)

mark(mkd)
<p><code>$x$</code> is inline math \(x\)!</p>
<p>Display style:</p>
<p>$$x + y$$</p>
<p>\begin{align}
a^{2}+b^{2} &amp; = c^{2}\\
\sin^{2}(x)+\cos^{2}(x) &amp; = 1
\end{align}</p>
mark(mkd, options = '-latex_math')
<p><code>$x$</code> is inline math $x$!</p>
<p>Display style:</p>
<p>$$x + y$$</p>
<p>\begin{align}
a^{2}+b^{2} &amp; = c^{2}\
\sin^{2}(x)+\cos^{2}(x) &amp; = 1
\end{align}</p>
# table example
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>
# caption
mark('
| a | b |
|---|--:|
| A | 9 |

Table: A table _caption_.
')
<table>
<caption>A table <em>caption</em>.</caption>
<thead>
<tr>
<th>a</th>
<th align="right">b</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td align="right">9</td>
</tr>
</tbody>
</table>
# no table
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
mark('https://www.r-project.org/')
<p><a href="https://www.r-project.org/">https://www.r-project.org/</a></p>
mark('https://www.r-project.org/', options = '-autolink')
<p>https://www.r-project.org/</p>
# links and spans
mark('[a b](#){.red}')
<p><a href="#" class="red">a b</a></p>
mark('[a\nb](){.red}')
<p><span class="red">a
b</span></p>
# strikethrough example
mark('~~awesome~~')
<p><del>awesome</del></p>
mark('~~awesome~~', options = '-strikethrough')
<p>~~awesome~~</p>
# superscript and subscript examples
mark('2^10^')
<p>2<sup>10</sup></p>
mark('2^10^', options = '-superscript')
<p>2^10^</p>
mark('H~2~O')
<p>H<sub>2</sub>O</p>
mark('H~2~O', options = '-subscript')
<p>H~2~O</p>
# code blocks
mark('```r\n1 + 1;\n```')
<pre><code class="language-r">1 + 1;
</code></pre>
mark('```{.r}\n1 + 1;\n```')
<pre><code class="language-r">1 + 1;
</code></pre>
mark('```{.r .js}\n1 + 1;\n```')
<pre><code class="language-r js">1 + 1;
</code></pre>
mark('```{.r .js #foo}\n1 + 1;\n```')
<pre><code class="language-r js" id="foo">1 + 1;
</code></pre>
mark('```{.r .js #foo style="background:lime;"}\n1 + 1;\n```')
<pre><code class="language-r js" id="foo" style="background:lime;">1 + 1;
</code></pre>
mark('````\nA _code chunk_:\n\n```{r, echo=TRUE}\n1 + 1;\n```\n````')
<pre><code>A _code chunk_:

```{r, echo=TRUE}
1 + 1;
```
</code></pre>
# raw blocks
mark('```{=html}\n<p>raw HTML</p>\n```')
<p>raw HTML</p>
mark('```{=latex}\n\\textbf{raw LaTeX}\n```')

# fenced Divs
mark('::: foo\nasdf\n:::')
<div class="foo">
<p>asdf</p>
</div>
mark('::: {.foo .bar #baz style="color: red;"}\nasdf\n:::')
<div id="baz" class="foo bar" style="color: red;">
<p>asdf</p>
</div>
# footnotes
mark('Hello[^foo] world!\n\n[^foo]: A _footnote_.')
<p>Hello<sup class="footnote-ref"><a href="#fn-foo" id="fnref-foo" data-footnote-ref>1</a></sup> world!</p>
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-foo">
<p>A <em>footnote</em>. <a href="#fnref-foo" class="footnote-backref" data-footnote-backref data-footnote-backref-idx="1" aria-label="Back to reference 1">↩</a></p>
</li>
</ol>
</section>
mark('Hello[^2] world!\n\n[^2]: A footnote with _multiple_ elements.\n\n    - list')
<p>Hello<sup class="footnote-ref"><a href="#fn-2" id="fnref-2" data-footnote-ref>1</a></sup> world!</p>
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-2">
<p>A footnote with <em>multiple</em> elements.</p>
<ul>
<li>list</li>
</ul>
<a href="#fnref-2" class="footnote-backref" data-footnote-backref data-footnote-backref-idx="1" aria-label="Back to reference 1">↩</a>
</li>
</ol>
</section>
# smartypants example
mark('1/2 (c)')
<p>1/2 (c)</p>
mark('1/2 (c)', options = '+smartypants')
<p>½ ©</p>
mkd <- paste(names(litedown:::pants), collapse = ' ')
mark(mkd, options = '+smartypants')
<p>½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ⅐ ⅑ ⅒ © ® ™</p>
# filter HTML tags
mkd = '<style>a {}</style><script type="text/javascript">console.log("No!");</script>\n[Hello](#)'
mark(mkd)
<style>a {}</style><script type="text/javascript">console.log("No!");</script>
<p><a href="#">Hello</a></p>
mark(mkd, options = 'tagfilter')
&lt;style>a {}&lt;/style>&lt;script type="text/javascript">console.log("No!");&lt;/script>
<p><a href="#">Hello</a></p>

0.2 HTML output of above examples

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

mark(mkd, options = '+number_sections')

1 Header 1

p1

1.1 Header 2

p2

mark(mkd, options = '+number_sections+toc')

1 Header 1

p1

1.1 Header 2

p2

# hard_wrap example
mark('foo\nbar\n')

foo bar

mark('foo\nbar\n', options = '+hardbreaks')

foo
bar

# latex math example
mkd <- c(
  '`$x$` is inline math $x$!', '', 'Display style:', '', '$$x + y$$', '',
  '\\begin{align}
a^{2}+b^{2} & = c^{2}\\\\
\\sin^{2}(x)+\\cos^{2}(x) & = 1
\\end{align}'
)

mark(mkd)

$x$ is inline math \(x\)!

Display style:

$$x + y$$

\begin{align} a^{2}+b^{2} & = c^{2}\\ \sin^{2}(x)+\cos^{2}(x) & = 1 \end{align}

mark(mkd, options = '-latex_math')

$x$ is inline math \(x\)!

Display style:

$$x + y$$

\begin{align} a^{2}+b^{2} & = c^{2}\ \sin^{2}(x)+\cos^{2}(x) & = 1 \end{align}

# table example
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
# caption
mark('
| a | b |
|---|--:|
| A | 9 |

Table: A table _caption_.
')
A table caption.
a b
A 9
# no table
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
mark('https://www.r-project.org/')

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

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

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

# links and spans
mark('[a b](#){.red}')

a b

mark('[a\nb](){.red}')

a b

# strikethrough example
mark('~~awesome~~')

awesome

mark('~~awesome~~', options = '-strikethrough')

~~awesome~~

# superscript and subscript examples
mark('2^10^')

210

mark('2^10^', options = '-superscript')

210

mark('H~2~O')

H2O

mark('H~2~O', options = '-subscript')

H2O

# code blocks
mark('```r\n1 + 1;\n```')
1 + 1;
mark('```{.r}\n1 + 1;\n```')
1 + 1;
mark('```{.r .js}\n1 + 1;\n```')
1 + 1;
mark('```{.r .js #foo}\n1 + 1;\n```')
1 + 1;
mark('```{.r .js #foo style="background:lime;"}\n1 + 1;\n```')
1 + 1;
mark('````\nA _code chunk_:\n\n```{r, echo=TRUE}\n1 + 1;\n```\n````')
A _code chunk_:

```{r, echo=TRUE}
1 + 1;
```
# raw blocks
mark('```{=html}\n<p>raw HTML</p>\n```')

raw HTML

mark('```{=latex}\n\\textbf{raw LaTeX}\n```')
# fenced Divs
mark('::: foo\nasdf\n:::')

asdf

mark('::: {.foo .bar #baz style="color: red;"}\nasdf\n:::')

asdf

# footnotes
mark('Hello[^foo] world!\n\n[^foo]: A _footnote_.')

Hello1 world!

  1. A footnote.

mark('Hello[^2] world!\n\n[^2]: A footnote with _multiple_ elements.\n\n    - list')

Hello1 world!

  1. A footnote with multiple elements.

    • list
# smartypants example
mark('1/2 (c)')

1/2 (c)

mark('1/2 (c)', options = '+smartypants')

½ ©

mkd <- paste(names(litedown:::pants), collapse = ' ')
mark(mkd, options = '+smartypants')

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

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

Hello

mark(mkd, options = 'tagfilter')

<style>a {}</style><script type=“text/javascript”>console.log(“No!”);</script>

Hello

0.3 LaTeX output of above examples

# temporarily override mark()
mark = function(...) litedown::mark(..., output = 'latex')
# toc example
mkd <- c('# Header 1', 'p1', '## Header 2', 'p2')

mark(mkd, options = '+number_sections')
\section{Header 1}

p1

\subsection{Header 2}

p2
mark(mkd, options = '+number_sections+toc')
\tableofcontents
\section{Header 1}

p1

\subsection{Header 2}

p2
# hard_wrap example
mark('foo\nbar\n')
foo
bar
mark('foo\nbar\n', options = '+hardbreaks')
foo\\
bar
# latex math example
mkd <- c(
  '`$x$` is inline math $x$!', '', 'Display style:', '', '$$x + y$$', '',
  '\\begin{align}
a^{2}+b^{2} & = c^{2}\\\\
\\sin^{2}(x)+\\cos^{2}(x) & = 1
\\end{align}'
)

mark(mkd)
\texttt{\$x\$} is inline math \(x\)!

Display style:

$$x + y$$

\begin{align}
a^{2}+b^{2} & = c^{2}\\
\sin^{2}(x)+\cos^{2}(x) & = 1
\end{align}
mark(mkd, options = '-latex_math')
\texttt{\$x\$} is inline math \$x\$!

Display style:

\$\$x + y\$\$

\textbackslash{}begin\{align\}
a\^{}\{2\}+b\^{}\{2\} \& = c\^{}\{2\}\textbackslash{}
\textbackslash{}sin\^{}\{2\}(x)+\textbackslash{}cos\^{}\{2\}(x) \& = 1
\textbackslash{}end\{align\}
# table example
mark('
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
')
\begin{tabular}{ll}
First Header & Second Header \\
Content Cell & Content Cell \\
Content Cell & Content Cell \\
\end{tabular}

# caption
mark('
| a | b |
|---|--:|
| A | 9 |

Table: A table _caption_.
')
\begin{tabular}{lr}
a & b \\
A & 9 \\
\end{tabular}

Table: A table \emph{caption}.
# no table
mark('
First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell
', options = '-table')
First Header  \textbar{} Second Header
------------- \textbar{} -------------
Content Cell  \textbar{} Content Cell
Content Cell  \textbar{} Content Cell
# autolink example
mark('https://www.r-project.org/')
\url{https://www.r-project.org/}
mark('https://www.r-project.org/', options = '-autolink')
https://www.r-project.org/
# links and spans
mark('[a b](#){.red}')
\protect\hyperlink{}{a b}\{.red\}
mark('[a\nb](){.red}')
{a
b}\{.red\}
# strikethrough example
mark('~~awesome~~')
\sout{awesome}
mark('~~awesome~~', options = '-strikethrough')
\textasciitilde{}\textasciitilde{}awesome\textasciitilde{}\textasciitilde{}
# superscript and subscript examples
mark('2^10^')
2\textsuperscript{10}
mark('2^10^', options = '-superscript')
2\^{}10\^{}
mark('H~2~O')
H\textsubscript{2}O
mark('H~2~O', options = '-subscript')
H\textasciitilde{}2\textasciitilde{}O
# code blocks
mark('```r\n1 + 1;\n```')
\begin{verbatim}
1 + 1;
\end{verbatim}
mark('```{.r}\n1 + 1;\n```')
\begin{verbatim}
1 + 1;
\end{verbatim}
mark('```{.r .js}\n1 + 1;\n```')
\begin{verbatim}
1 + 1;
\end{verbatim}
mark('```{.r .js #foo}\n1 + 1;\n```')
\begin{verbatim}
1 + 1;
\end{verbatim}
mark('```{.r .js #foo style="background:lime;"}\n1 + 1;\n```')
\begin{verbatim}
1 + 1;
\end{verbatim}
mark('````\nA _code chunk_:\n\n```{r, echo=TRUE}\n1 + 1;\n```\n````')
\begin{verbatim}
A _code chunk_:

```{r, echo=TRUE}
1 + 1;
```
\end{verbatim}
# raw blocks
mark('```{=html}\n<p>raw HTML</p>\n```')

mark('```{=latex}\n\\textbf{raw LaTeX}\n```')
\textbf{raw LaTeX}
# fenced Divs
mark('::: foo\nasdf\n:::')
\begin{verbatim}
::: {.foo} :::
\end{verbatim}

asdf
\end
mark('::: {.foo .bar #baz style="color: red;"}\nasdf\n:::')
\begin{verbatim}
::: {.foo .bar #baz style="color: red;"} :::
\end{verbatim}

asdf
\end
# footnotes
mark('Hello[^foo] world!\n\n[^foo]: A _footnote_.')
Hello\footnote{A \emph{footnote}.} world!
mark('Hello[^2] world!\n\n[^2]: A footnote with _multiple_ elements.\n\n    - list')
Hello\footnote{A footnote with \emph{multiple} elements.

\begin{itemize}
\item list

\end{itemize}} world!
# smartypants example
mark('1/2 (c)')
1/2 (c)
mark('1/2 (c)', options = '+smartypants')
½ ©
mkd <- paste(names(litedown:::pants), collapse = ' ')
mark(mkd, options = '+smartypants')
½ ⅓ ⅔ ¼ ¾ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ⅐ ⅑ ⅒ © ® ™
# filter HTML tags
mkd = '<style>a {}</style><script type="text/javascript">console.log("No!");</script>\n[Hello](#)'
mark(mkd)
\protect\hyperlink{}{Hello}
mark(mkd, options = 'tagfilter')
\protect\hyperlink{}{Hello}
rm(mark)