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:
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 anError
with the messagemessage
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.
npm:
npm install remark-disable-tokenizers
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)
-
autoLink
is not working correctly -- in order to disable auto-linking, you have to passurl
to the array of disabled inline tokenizers.
unified()
.use(remarkParse)
.use(remarkDisableTokenizers, {
inline: ['url']
})
.use(remark2rehype)
.use(stringify)