Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/r-lib/commonmark

High Performance CommonMark and Github Markdown Rendering in R
https://github.com/r-lib/commonmark

cmark cmark-gfm gfm markdown

Last synced: about 23 hours ago
JSON representation

High Performance CommonMark and Github Markdown Rendering in R

Awesome Lists containing this project

README

        

# commonmark

> High Performance CommonMark and Github Markdown Rendering in R

[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/commonmark)](https://cran.r-project.org/package=commonmark)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/commonmark)](https://cran.r-project.org/package=commonmark)

The CommonMark specification defines a rationalized version of markdown
syntax. This package uses the 'cmark' reference implementation for converting
markdown text into various formats including html, latex and groff man. In
addition it exposes the markdown parse tree in xml format. The latest version of
this package also adds support for Github extensions including tables, autolinks
and strikethrough text.

## Documentation

- [The `commonmark` R package](https://docs.ropensci.org/commonmark/)
- [CommonMark specification for Markdown text](https://commonmark.org/help/)
- [Extensions for GitHub Flavored Markdown](https://github.github.com/gfm/)

## Basic Markdown

```r
library(commonmark)
md <- "## Test
An *example* text for the `commonmark` package."

# Convert to Latex
cat(markdown_latex(md))
```

```
\subsection{Test}

An \emph{example} text for the \texttt{commonmark} package.
```

```r
# Convert to HTML
cat(markdown_html(md))
```

```

Test


An example text for the commonmark package.


```

```r
# Convert to 'groff' man
cat(markdown_man(md))
```

```
.SS
Test
.PP
An \f[I]example\f[] text for the \f[C]commonmark\f[] package.
```

```r
# Convert back to (normalized) markdown
cat(markdown_commonmark(md))
```

```
## Test

An *example* text for the `commonmark` package.
```

```r
# The markdown parse tree
cat(markdown_xml(md))
```

```


Test


An

example

text for the
commonmark
package.

```

## Github Extensions

Commonmark includes several 'extensions' to enable features which are not (yet) part of the official specification. The current version of the commonmark R package offers 4 such extensions:

- __table__ support rendering of tables
- __strikethough__ via `~sometext~` syntax
- __autolink__ automatically turn URLs into hyperlinks
- __tagfilter__ blacklist html tags: `title` `textarea` `style` `xmp` `iframe` `noembed` `noframes` `script` `plaintext`.
- __tasklist__ turns certain list items into checkboxes

These extensions were added by Github to support [GitHub Flavored Markdown](https://github.github.com/gfm/).

```r
table <- '
aaa | bbb | ccc | ddd | eee
:-- | --- | :-: | --- | --:
fff | ggg | hhh | iii | jjj'

cat(markdown_latex(table, extensions = TRUE))
```

```
\begin{table}
\begin{tabular}{llclr}
aaa & bbb & ccc & ddd & eee \\
fff & ggg & hhh & iii & jjj \\
\end{tabular}
\end{table}
```

```r
cat(markdown_html(table, extensions = TRUE))
```

```

aaa
bbb
ccc
ddd
eee

fff
ggg
hhh
iii
jjj

```