remark plugin to enable, disable, and ignore messages with comments.
- What is this?
- When should I use this?
- Install
- Use
- API
- Syntax
- Types
- Compatibility
- Security
- Related
- Contribute
- License
This package is a unified (remark) plugin that lets authors write comments in markdown to show and hide messages.
You can use this package when youβre building a linter such as
remark-lint.
But you probably donβt need to, because remark-lint already exists and it uses
this package.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install remark-message-controlIn Deno with esm.sh:
import remarkMessageControl from 'https://esm.sh/remark-message-control@8'In browsers with esm.sh:
<script type="module">
import remarkMessageControl from 'https://esm.sh/remark-message-control@8?bundle'
</script>Say we have the following file example.md:
<!--foo ignore-->
## Neptuneβ¦and a module example.js:
/**
* @typedef {import('mdast').Root} Root
*/
import {remark} from 'remark'
import remarkMessageControl from 'remark-message-control'
import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
const file = await remark()
.use(function () {
/** @param {Root} tree */
return function (tree, file) {
file.message('Whoops!', {
place: tree.children[1]?.position,
ruleId: 'thing',
source: 'foo'
})
}
})
.use(remarkMessageControl, {name: 'foo'})
.process(await read('example.md'))
console.error(reporter(file))β¦then running node example.js yields:
example.md: no issues foundπ Note: without
remarkMessageControl, weβd see:example.md 3:1-3:11 warning Whoops! thing foo β 1 warning
This package exports no identifiers.
The default export is remarkMessageControl.
Enable, disable, and ignore messages with comments.
options(Options, required) β configuration
Transform (Transformer).
Configuration (TypeScript type).
enable(Array<string>, optional) β list ofruleIds to initially turn on; used ifresetistruedisable(Array<string>, optional) β list ofruleIds to initially turn off; used ifresetis nottrueknown(Array<string>, optional) β list of allowedruleIdsname(string, required) β name of markers that can control the message sourcesreset(boolean, default:false) β whether to treat all messages as turned off initiallysource(Array<string>orstring, default:options.name) β sources that can be controlled with markers
This plugin looks for comments in markdown (MDX is also supported).
If the first word in those comments does not match options.name, the comment
is skipped.
The second word is expected to be disable, enable, or ignore.
Further words are rule identifiers of messages which are configurated.
In EBNF, the grammar looks as follows:
marker ::= identifier whitespace+ keyword ruleIdentifiers?
identifier ::= word+ /* restriction: must match `options.name` */
keyword ::= 'enable' | 'disable' | 'ignore'
ruleIdentifiers ::= word+ (whitespace+ word+)*
whitespace ::= ' ' | '\t' | '\r' | '\n' | '\f'
word ::= letter | digit | punctuation
letter ::= letterLowercase | letterUppercase
punctuation ::= '-' | '_'
letterLowercase ::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'
letterUppercase ::= 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
Which keyword is used defines how messages with those rule identifiers are handled:
The disable keyword turns off all messages of the given rule identifiers. When without identifiers, all messages are turned off.
For example, to turn off certain messages:
<!--lint disable list-item-bullet-indent strong-marker-->
* **foo**
A paragraph, and now another list.
* __bar__The enable keyword turns on all messages of the given rule identifiers. When without identifiers, all messages are turned on.
For example, to enable certain messages:
<!--lint enable strong-marker-->
**foo** and __bar__.The ignore keyword turns off all messages of the given ruleIds occurring
in the following node.
When without ruleIds, all messages are ignored.
Messages are turned on again after the end of the following node.
For example, to turn off certain messages for the next node:
<!--lint ignore list-item-bullet-indent strong-marker-->
* **foo**
* __bar__This package is fully typed with TypeScript.
It exports the additional type Options.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, remark-message-control@^8,
compatible with Node.js 16.
This plugin works with unified version 6+ and remark version 7+.
Use of remark-message-control does not involve rehype (hast)
or user content so there are no openings for cross-site scripting
(XSS) attacks.
Messages may be hidden from user content though, causing builds to fail or pass,
or changing a report.
remark-lintβ plugin to lint code stylemdast-comment-markerβ mdast utility to parse comment markers
See contributing.md in remarkjs/.github for ways
to get started.
See support.md for ways to get help.
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