JSPM

  • Created
  • Published
  • Downloads 332203
  • Score
    100M100P100Q176953F
  • License MIT

Compile Markdown to HTML with remark

Package Exports

  • remark-html

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remark-html) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

remark-html Build Status Coverage Status

Compiles markdown to HTML. Built on remark, an extensively tested and pluggable parser.

Installation

npm:

npm install remark-html

remark-html is also available as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

Dependencies:

var remark = require('remark');
var html = require('remark-html');

Process.

var doc = remark().use(html).process([
    '# Hello & World',
    '',
    '**Alpha**, _bravo_, and ~~Charlie~~.'
].join('\n'));

Yields:

<h1>Hello &amp; World</h1>
<p><strong>Alpha</strong>, <em>bravo</em>, and <del>Charlie</del>.</p>

API

remark.use(html[, options])

options (Object?):

  • entities (true, 'numbers', or 'escape', default: true) — How to encode non-ASCII and HTML-escape characters: the default generates named entities (& > &amp;); 'numbers' generates numbered entities (& > &#x26;), and 'escape' only encodes characters which are required by HTML to be escaped: &, <, >, ", ', and `, leaving non-ASCII characters untouched.

  • xhtml (boolean, default: false) — Whether or not to terminate self-closing tags (such as img) with a slash;

  • sanitize (boolean, default: false) — Whether or not to allow the use of HTML inside markdown.

CommonMark

You still need to set commonmark: true in remarks options.

CommonMark support is a goal but not (yet) a necessity. There are some (roughly 115 of 550, relating to inline precedence, lists, emphasis and strongness) issues which I’d like to cover in the future. Note that this sounds like a lot, but they have to do with obscure differences which do not often occur in the real world. Read more on some of the reasoning in doc/commonmark.md.

Integrations

remark-html works great with:

All MDAST nodes can be compiled to HTML. Unknown MDAST nodes are compiled to div nodes.

In addition, remark-html can be told how to compile nodes through three data properties:

  • htmlName — Tag-name to compile as;
  • htmlContent — HTML content to add (instead of children and value);
  • htmlAttributes — Map of attributes to add.

For example, the following node:

{
  "type": "emphasis",
  "data": {
    "htmlName": "i",
    "htmlAttributes": {
      "id": "foo"
    },
    "htmlContent": "bar"
  },
  "children": [{
    "type": "text",
    "value": "baz",
  }]
}

...would yield:

<i id="foo">bar</i>

License

MIT © Titus Wormer