remark plugin to compile Markdown
Last updated a month ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install remark-stringify 
SYNC missed versions from official npm registry.


Build Coverage Downloads Size Chat Sponsors Backers

Compiler for unified. Serializes mdast syntax trees to Markdown. Used in the remark processor but can be used on its own as well. Can be extended to change how Markdown is serialized.











npm install remark-stringify


var unified = require('unified')
var createStream = require('unified-stream')
var html = require('rehype-parse')
var rehype2remark = require('rehype-remark')
var stringify = require('remark-stringify')

var processor = unified()
  .use(stringify, {
    bullet: '*',
    fence: '~',
    fences: true,
    incrementListMarker: false


See unified for more examples »



See unified for API docs »

processor().use(stringify[, options])

Configure the processor to serialize mdast syntax trees to Markdown.


Options can be passed directly, or passed later through


Serialize with the required escapes for GFM compatible Markdown (boolean, default: true).

  • Escape pipes (|, for tables)
  • Escape colons (:, for literal URLs)
  • Escape tildes (~, for strike-through)

Serialize for CommonMark compatible Markdown (boolean, default: false).

  • Serialize adjacent block quotes separately
  • Escape more characters using slashes, instead of as entities

⚠️ Pedantic was previously used to mimic old-style Markdown mode: no tables, no fenced code, and with many bugs. It’s currently still “working”, but please do not use it, it’ll be removed in the future.


How to serialize entities (string or boolean, default: false):

  • true — Entities are generated for special HTML characters (& > &) and non-ASCII characters (© > ©). If named entities are not (widely) supported, numbered character references are used ( > ’)
  • 'numbers' — Numbered entities are generated (& > &) for special HTML characters and non-ASCII characters
  • 'escape' — Special HTML characters are encoded (& > &, > ’), non-ASCII characters not (ö persists)

Serialize headings, when possible, in Setext-style (boolean, default: false). Uses = for level one headings and - for level two headings. Other heading levels are serialized as ATX (respecting closeAtx).


Serialize ATX headings with the same amount of closing hashes as opening hashes (boolean, default: false).


Create tables with a space between cell delimiters (|) and content (boolean, default: true).


Align the delimiters (|) between table cells so that they all align nicely and form a grid (boolean, default: true).


Function passed to markdown-table to detect the length of a table cell (Function, default: s => s.length). Used to pad tables.


Marker to use for fenced code blocks ('~' or '`', default: '`').


Create code blocks with a fence instead of indentation if they have no info string (boolean, default: false).

When false, code blocks are indented. Code blocks with an info string are always fenced.


Marker to use for the bullet of unordered list items ('-', '*', or '+', default: '-').


Style of indentation for list items ('tab', 'mixed' or '1', default: 'tab').

  • 'tab': use a tab stops (4 spaces)
  • '1': use one space
  • 'mixed': use 1 for tight and tab for loose list items

Increment ordered list item numbers (boolean, default: true).

When false, all list item numbers will be the same.


Separate definitions with a single line feed (boolean, default: false).

When false, definitions will have blank lines between them, similar to other blocks.


Marker to use for thematic breaks / horizontal rules ('-', '*', or '_', default: '*').


Number of markers to use for thematic breaks / horizontal rules (number, default: 3). Musts be 3 or more.


Place a space between thematic break (horizontal rule) markers (boolean, default true).


Marker to use for importance ('_' or '*', default '*').


Marker to use for emphasis ('_' or '*', default '_').


Access to the compiler, if you need it.

Extending the Compiler

If the remark-stringify plugin is used, it adds a Compiler constructor function to the processor. Other plugins can add visitors to its prototype to change how Markdown is serialized.

The below plugin modifies a visitor to add an extra blank line before headings with a rank of 2.

module.exports = gap

function gap() {
  var Compiler = this.Compiler
  var visitors = Compiler.prototype.visitors
  var original = visitors.heading

  visitors.heading = heading

  function heading(node) {
    return (node.depth === 2 ? '\n' : '') + original.apply(this, arguments)


Map of types to visitors (Object.<Function>).

function visitor(node[, parent])

Serialize node.

  • node (Node) — Node to compile
  • parent (Parent, optional) — Parent of node. Not available on the root node

string — Serialized given node.


As Markdown is sometimes used for HTML, and improper use of HTML can open you up to a cross-site scripting (XSS) attack, use of remark can also be unsafe. When going to HTML, use remark in combination with the rehype ecosystem, and use rehype-sanitize to make the tree safe.

Use of remark plugins could also open you up to other attacks. Carefully assess each plugin and the risks involved in using them.


See in remarkjs/.github for ways to get started. See for ways to get help. Ideas for new plugins and tools can be posted in remarkjs/ideas.

A curated list of awesome remark resources can be found in awesome remark.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer

Current Tags

  • 8.1.0                                ...           latest (a month ago)

24 Versions

  • 8.1.0                                ...           a month ago
  • 8.0.0                                ...           3 months ago
  • 7.0.4                                ...           8 months ago
  • 7.0.3                                ...           a year ago
  • 7.0.2                                ...           a year ago
  • 7.0.1                                ...           a year ago
  • 7.0.0                                ...           a year ago
  • 6.0.4                                ...           2 years ago
  • 6.0.3                                ...           2 years ago
  • 6.0.2                                ...           2 years ago
  • 6.0.1                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.0.0                                ...           2 years ago
  • 4.0.0                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.0.0                                ...           4 years ago
Maintainers (2)
Today 815
This Week 38,174
This Month 63,120
Last Day 2,159
Last Week 38,575
Last Month 164,951
Dependencies (14)
Dev Dependencies (0)
Dependents (201)

Copyright 2014 - 2016 © |