npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@enkidevs/remark-stringify

v8.0.0

Published

remark plugin to compile Markdown

Downloads

111

Readme

remark-stringify

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.

Sponsors

Install

npm:

npm install remark-stringify

Use

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(html)
  .use(rehype2remark)
  .use(stringify, {
    bullet: '*',
    fence: '~',
    fences: true,
    incrementListMarker: false
  })

process.stdin.pipe(createStream(processor)).pipe(process.stdout)

See unified for more examples »

Contents

API

See unified for API docs »

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

Configure the processor to serialize mdast syntax trees to Markdown.

options

Options can be passed directly, or passed later through processor.data().

options.gfm

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)
options.commonmark

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

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

⚠️ 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.

options.entities

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)
options.setext

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).

options.closeAtx

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

options.tableCellPadding

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

options.tablePipeAlign

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

options.stringLength

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

options.fence

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

options.fences

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.

options.bullet

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

options.listItemIndent

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
options.incrementListMarker

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

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

options.rule

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

options.ruleRepetition

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

options.ruleSpaces

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

options.strong

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

options.emphasis

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

stringify.Compiler

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)
  }
}

Compiler#visitors

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

function visitor(node[, parent])

Serialize node.

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

string — Serialized given node.

Security

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.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md 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.

License

MIT © Titus Wormer