Lazy-loaded Markdown → HTML parser with GFM and syntax highlighting.
npm i @nodedk/markdown
var markdown = require('@nodedk/markdown')
var parser = markdown()
var html = parser.block('# Hello')
var inline = parser.inline('Hello **world**')
Output:
<h1>Hello</h1>
Create separately configured parsers by passing Marked options:
var parser = markdown({ breaks: false })
markdown(options = {}) returns a parser with block(source) and
inline(source). Both accept Markdown strings. The defaults are:
var options = {
breaks: true,
gfm: true,
pedantic: false,
silent: false
}
Options override these defaults. Marked renderers, tokenizers, hooks, and
extensions are supported. A custom renderer.code overrides the built-in
syntax highlighting. Set renderer: null to use Marked's renderer without
syntax highlighting.
parser.block() returns an HTML string by default. With { async: true }, it
returns a Promise as defined by Marked.
Use parser.inline() for inline HTML without paragraph wrappers. Newlines use
<br> tags because breaks is enabled by default:
parser.inline('one\ntwo')
// one<br>two
Fenced code blocks are highlighted with Highlight.js:
```js
var x = 1
```
js, ts, py, rb, sh, and yml.Use xml for HTML and markdown for Markdown code blocks.
Copy a Highlight.js stylesheet into the application’s public assets:
mkdir -p app/assets/css
cp node_modules/highlight.js/styles/github.css app/assets/css/highlight.css
Add /css/highlight.css to app/config/bundle.js in a NodeDK application,
or load the copied stylesheet directly:
<link rel="stylesheet" href="/css/highlight.css" />
Raw HTML in Markdown is allowed. Only parse trusted Markdown, or sanitize the rendered HTML before displaying it.
Created by Vidar Eldøy