remark-disable-tokenizers

1.1.0 • Public • Published

remark-disable-tokenizers Build Status Coverage Status

This remark plugin can disable any or all remark blockTokenizers and inlineTokenizers. It can not only disable the ones provided by remark core, but also any other tokenizer that has been added to the remark parser whether through plugins or not.

Remark default tokenizers that can be disabled are listed here:

Configuration

Two options can be passed, as a single argument object:

{block = [], inline = []}

Each of these can contain both tokenizer names as strings or arrays ['tokenizerName', 'error message'].

  • A string name: this tokenizer will be disabled
  • An array [name, message]: this tokenizer, if used, will throw an Error with the message message

Motivation

In some situations it might be interesting to only parse inline Markdown syntax. We created it for the purpose of parsing/rendering forum signatures -- short textual content people can use to sign their messages on web forums. In this context it made no sense to allow elements that would eat up a lot of vertical space.

Installation

npm:

npm install remark-disable-tokenizers

Usage

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

const remarkDisableBlocks = require('remark-disable-tokenizers')

Usage:

unified()
  .use(remarkParse)
  .use(remarkDisableTokenizers, {
    block: [
      'indentedCode',
      'fencedCode',
      // I'd like to ignore a bunch of blockTokenizers but specifically
      // I want blockquotes to throw this `Error` if used in the input Markdown
      ['blockquote', 'Blockquote are not allowed!'],
      'atxHeading',
      'setextHeading',
      'footnote',
      'table',
      'custom_blocks'
    ],
    inline: [
      'emphasis' // emphasis is the only inlineTokenizer I'm disallowing
    ]
  })
  .use(remark2rehype)
  .use(stringify)

Caveats

  • autoLink is not working correctly -- in order to disable auto-linking, you have to pass url to the array of disabled inline tokenizers.
unified()
  .use(remarkParse)
  .use(remarkDisableTokenizers, {
    inline: ['url']
  })
  .use(remark2rehype)
  .use(stringify)

License

MIT © Zeste de Savoir

Readme

Keywords

Package Sidebar

Install

npm i remark-disable-tokenizers

Weekly Downloads

9,626

Version

1.1.0

License

MIT

Unpacked Size

9.06 kB

Total Files

5

Last publish

Collaborators

  • situphen
  • talone