0.29.0 • Published 5 years ago
@mvasilkov/cmark-gfm v0.29.0
cmark-gfm
GitHub Flavored Markdown ¦ Native bindings for cmark-gfm, GitHub's fork of cmark, a CommonMark parsing and rendering library
Installation
npm add @mvasilkov/cmark-gfmUsage
const { renderHtmlSync } = require('@mvasilkov/cmark-gfm')
const html = renderHtmlSync('# hello, world')
// returns <h1>hello, world</h1>Asynchronous usage
const { renderHtml } = require('@mvasilkov/cmark-gfm')
// With async/await
const html = await renderHtml('# hello, world')
// With Promises
renderHtml('# hello, world').then(html => {})
// With node-style callbacks
renderHtml('# hello, world', (err, html) => {})Passing options
renderHtmlSync('# hello, world', { sourcepos: true })
// returns <h1 data-sourcepos="1:1-1:14">hello, world</h1>
await renderHtml('# hello, world', { sourcepos: true })
// equivalent to the aboveAll available options are listed below.
Using extensions
renderHtmlSync('# hello, https://sr.ht/', {
  extensions: { autolink: true }
})
// returns <h1>hello, <a href="https://sr.ht/">https://sr.ht/</a></h1>
await renderHtml('# hello, https://sr.ht/', {
  extensions: { autolink: true }
})
// equivalent to the aboveSupported extensions are listed below.
Usage with streams
const fs = require('fs')
const { StreamingParser } = require('@mvasilkov/cmark-gfm')
fs.createReadStream('README.md')
  .pipe(new StreamingParser({ extensions: { table: true } }))
  .pipe(fs.createWriteStream('README.html'))Options
All of the following options are boolean, and off by default.
Options affecting rendering
| Option | Što | 
|---|---|
| sourcepos | Include a data-sourceposattribute on all block elements. | 
| hardbreaks | Render softbreakelements as hard line breaks. | 
| unsafe | Render raw HTML and unsafe links. | 
| nobreaks | Render softbreakelements as spaces. | 
| react | Produce React-compatible output (JSX). | 
Options affecting parsing
| Option | Što | 
|---|---|
| validateUtf8 | Validate UTF-8 in the input before parsing, replacing illegal sequences with the replacement character U+FFFD. | 
| smart | Convert straight quotes to curly, ---to em dashes,--to en dashes. | 
| githubPreLang | Use GitHub-style <pre lang="x">tags for code blocks instead of<pre><code class="language-x">. | 
| liberalHtmlTag | Be liberal in interpreting inline HTML tags. | 
| footnotes | Parse footnotes. | 
| strikethroughDoubleTilde | Only parse strikethroughs if surrounded by exactly 2 tildes. Gives some compatibility with redcarpet. | 
| tablePreferStyleAttributes | Use styleattributes to align table cells instead ofalignattributes. | 
| fullInfoString | Include the remainder of the info string in code blocks in a separate attribute. | 
Extensions
| Extension | Što | 
|---|---|
| autolink | Output web addresses and emails as hyperlinks. | 
| strikethrough | Enable the ~~strikethrough~~syntax. | 
| table | Enable tables. | 
| tagfilter | Escape the following HTML tags: title,textarea,style,xmp,iframe,noembed,noframes,script, andplaintext. | 
| tasklist | Enable task lists. | 
Authors
This is a fork of Michelle Tilley's repo. It's entirely compatible with the upstream, and brings the following improvements:
- Convert to TypeScript
- Update the underlying C library to the latest master
- Exclude dead code from compilation
- Reduce dev dependencies' footprint
- Optional React (JSX) support
Maintained by Mark Vasilkov.
License
MIT
0.29.0
5 years ago
0.9.0
5 years ago
0.29.0-gfm.0.2
6 years ago
0.29.0-gfm.0.1
6 years ago
0.29.0-gfm.0
6 years ago