Compiler for unified. Stringifies 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 parsed.
Announcing the unified collective! 🎉 Read more about it on Medium »
🥇 ZEIT |
🥇 Gatsby |
🥉 Compositor |
Holloway |
You? |
npm:
npm install remark-stringify
var unified = require('unified')
var createStream = require('unified-stream')
var parse = require('remark-parse')
var toc = require('remark-toc')
var stringify = require('remark-stringify')
var processor = unified()
.use(parse)
.use(toc)
.use(stringify, {
bullet: '*',
fence: '~',
fences: true,
incrementListMarker: false
})
process.stdin.pipe(createStream(processor)).pipe(process.stdout)
Configure the processor
to stringify mdast syntax trees
to markdown.
Options are passed directly, or passed later through processor.data()
.
Stringify 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)
Stringify for CommonMark compatible markdown (boolean
, default: false
).
- Compile adjacent blockquotes separately
- Escape more characters using slashes, instead of as entities
Stringify for pedantic compatible markdown (boolean
, default: false
).
- Escape underscores in words
How to stringify 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)
Compile headings, when possible, in Setext-style (boolean
, default: false
).
Uses =
for level one headings and -
for level two headings. Other heading
levels are compiled as ATX (respecting closeAtx
).
Compile ATX headings with the same amount of closing hashes as opening hashes
(boolean
, default: false
).
Create tables without fences: initial and final pipes (boolean
, default:
false
).
Create tables without spacing between pipes and content (boolean
, default:
true
).
Create tables with padding in each cell so that they are the same size
(boolean
, default: true
).
Function passed to markdown-table
to detect the length of a
table cell (Function
, default: s => s.length
).
Fence marker to use for code blocks ('~'
or '`'
, default: '`'
).
Stringify code blocks without language with fences (boolean
, default:
false
).
Bullet marker to use for unordered list items ('-'
, '*'
, or '+'
,
default: '-'
).
How to indent the content from list items ('tab'
, 'mixed'
or '1'
,
default: 'tab'
).
'tab'
: use tab stops (4 spaces)'1'
: use one space'mixed'
: use1
for tight andtab
for loose list items
Whether to increment ordered list item bullets (boolean
, default: true
).
Marker to use for thematic breaks / horizontal rules ('-'
, '*'
, or '_'
,
default: '*'
).
Number of markers to use for thematic breaks / horizontal rules (number
,
default: 3
). Should be 3
or more.
Whether to pad thematic break (horizontal rule) markers with spaces (boolean
,
default true
).
Marker to use for importance ('_'
or '*'
, default '*'
).
Marker to use for emphasis ('_'
or '*'
, default '_'
).
Access to the raw compiler, if you need it.
If this plugin is used, it adds a Compiler
constructor
to the processor
. Other plugins can change and add visitors on
the compiler’s prototype to change how markdown is stringified.
The below plugin modifies a visitor to add an extra blank line before level two headings.
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)
}
}
An object mapping node types to visitor
s.
Stringify node
.
string
, the compiled given node
.