unified utility to enable, disable, and ignore messages.
Contents What is this?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.
InstallThis package is ESM only. In Node.js (version 16+), install with npm:
npm install unified-message-control
In Deno with esm.sh
:
import {messageControl} from 'https://esm.sh/unified-message-control@5'
In browsers with esm.sh
:
<script type="module"> import {messageControl} from 'https://esm.sh/unified-message-control@5?bundle' </script>Use
Say our document example.md
contains:
<!--foo ignore--> ## Heading
â¦and our module example.js
looks as follows:
import {commentMarker} from 'mdast-comment-marker' import remarkParse from 'remark-parse' import remarkStringify from 'remark-stringify' import {read} from 'to-vfile' import {unified} from 'unified' import {messageControl} from 'unified-message-control' import {reporter} from 'vfile-reporter' 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 foundAPI
This package exports no identifiers. It exports the identifier messageControl
.
messageControl(tree, options)
Let comment markers control messages.
Parameters ReturnsNothing (undefined
).
Marker
Comment marker (TypeScript type).
NotesThe disable keyword turns off messages. For example:
<!--lint disable list-item-bullet-indent strong-marker--> * **foo** A paragraph, and now another list. * __bar__
The enable keyword turns on messages. For example:
<!--lint enable strong-marker--> **foo** and __bar__.
The ignore keyword turns off messages in the following node. After the end of the following node, messages are turned on again. For example:
<!--lint ignore list-item-bullet-indent strong-marker--> * **foo** * __bar__Fields
name
(string
) â name of markerattributes
(string
) â raw values (space-separated); the first should be enable
, disable
, or ignore
, the rest are optional rule identifiersMarkerParser
Parse a possible comment marker (TypeScript type).
Parametersnode
(Node
) â potential markerMarker
(Marker
, optional).
Options
Configuration (TypeScript type).
NotesThe given name
defines which comments work. Assuming thereâs a marker
configured that parses HTML comments such as <!--x y z-->
to a mark with name: 'x'
, then giving name: 'x'
will use comments such as:
When known
is given, a warning is shown when unknown rules are controlled. For example, {name: 'alpha', known: ['bravo']}
results in a warning (for charlie
):
<!--alpha ignore charlie-->Fields
enable
(Array<string>
, optional) â list of ruleId
s to initially turn on; used if reset
is true
disable
(Array<string>
, optional) â list of ruleId
s to initially turn off; used if reset
is not true
known
(Array<string>
, optional) â list of allowed ruleId
sfile
(VFile
, required) â corresponding filemarker
(MarkerParser
, required) â parse nodes to Marker
objectsname
(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>
or string
, default: options.name
) â sources that can be controlled with markerstest
(Test
, optional) â test for possible markersThis package is fully typed with TypeScript. It exports the additional types Marker
, MarkerParser
, and 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, unified-message-control@^5
, compatible with Node.js 16.
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.
LicenseMIT © Titus Wormer
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4