unified utility to enable, disable, and ignore messages.
This is a lego block that is meant to be extended, such as is done by
remark-message-control
, so that lint messages can be
controlled from content.
You can use this if you’re building an ecosystem like remark for some different content type, and want to let authors control messages from that content.
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:
npm install unified-message-control
In Deno with esm.sh
:
import messageControl from 'https://esm.sh/unified-message-control@4'
In browsers with esm.sh
:
<script type="module">
import messageControl from 'https://esm.sh/unified-message-control@4?bundle'
</script>
Say our document example.md
contains:
<!--foo ignore-->
## Heading
…and our module example.js
looks as follows:
import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {commentMarker} from 'mdast-comment-marker'
import {unified} from 'unified'
import messageControl from 'unified-message-control'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
const file = await read('example.md')
await unified()
.use(remarkParse)
.use(remarkStringify)
.use(function () {
return function (tree, file) {
file.message('Whoops!', tree.children[1], 'foo:thing')
}
})
.use(messageControl, {
marker: commentMarker,
name: 'foo',
test: 'html'
})
.process(file)
console.error(reporter(file))
…now running node example.js
yields:
example.md: no issues found
This package exports no identifiers.
The default export is messageControl
.
Let comment markers control messages from certain sources.
Configuration.
Name of markers that can control the message sources (string
).
For example, {name: 'alpha'}
controls alpha
markers:
<!--alpha ignore-->
Test for possible markers (Function
, string
, Object
, or Array<Test>
).
See unist-util-is
.
Parse a possible marker to a comment marker object (Function
).
If the possible marker actually isn’t a marker, should return undefined
.
List of allowed ruleId
s (Array<string>
, optional).
When given, a warning is shown when someone tries to control an unknown rule.
For example, {known: ['bravo'], name: 'alpha'}
results in a warning if
charlie
is configured:
<!--alpha ignore charlie-->
Whether to treat all messages as turned off initially (boolean
, default:
false
).
List of ruleId
s to initially turn on if reset: true
(Array<string>
, optional).
By default (reset: false
), all rules are turned on.
List of ruleId
s to turn on if reset: false
(Array<string>
, optional).
Sources that can be controlled with name
markers (string
or
Array<string>
, default: options.name
)
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 ruleId
s occurring
in the following node.
When without ruleId
s, all messages are ignored.
After the end of the following node, messages are turned on again.
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 types Marker
, MarkerParser
, and Options
.
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.
See contributing.md
in unifiedjs/.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.