Enable, disable, and ignore messages with unified.
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install unified-message-control
Say we have the following file, example.md
:
<!--foo ignore-->
## Heading
And our script, example.js
, looks as follows:
import {toVFile} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import {messageControl} from 'unified-message-control'
import {commentMarker} from 'mdast-comment-marker'
remark()
.use(warn)
.use(messageControl, {name: 'foo', marker: commentMarker, test: 'html'})
.process(toVFile.readSync('example.md'), function (err, file) {
console.error(reporter(err || file))
})
function warn() {
return function (tree, file) {
file.message('Whoops!', tree.children[1], 'foo:thing')
}
}
Now, running node example
yields:
example.md: no issues found
This package exports the following identifiers: messageControl
.
There is no default export.
Let comment markers control messages from certain sources.
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 null
.
List of allowed ruleId
s (Array.<string>
, optional).
When given, a warning is shown when someone tries to control an unknown rule.
For example, {name: 'alpha', known: ['bravo']}
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__
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.