mdast utility to parse a comment marker
npm install mdast-comment-marker[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[mdast][] utility to parse comment markers.
* What is this?
* When should I use this?
* Install
* Use
* API
* commentMarker(value)
* Marker
* MarkerParameters
* MarkerParameterValue
* Types
* Compatibility
* Security
* Related
* Contribute
* License
This package is a utility that tries to parse a structured marker from a
comment.
Comments are a hidden part of markdown, so they can be used as processing
instructions.
For example, this utility is used in [remark-lint][remark-lint] to control
whether lint rules are turned on or ignored, and by [mdast-zone][mdast-zone]
to replace sections between two markers.
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
``sh`
npm install mdast-comment-marker
In Deno with [esm.sh][esmsh]:
`js`
import {commentMarker} from 'https://esm.sh/mdast-comment-marker@3'
In browsers with [esm.sh][esmsh]:
`html`
`js
import {commentMarker} from 'mdast-comment-marker'
console.log(commentMarker({type: 'html', value: ''}));
console.log(commentMarker({
type: 'html',
value: ''
}));
console.log(commentMarker({type: 'html', value: ''}));
// Also supports MDX expressions:
console.log(commentMarker({
type: 'mdxFlowExpression',
value: '/ lint disable heading-style /'
}));
`
Yields:
`jsbar baz=12.4 qux="test test" quux='false'
{
name: 'foo',
attributes: '',
parameters: {},
node: { type: 'html', value: '' }
}
{
name: 'foo',
attributes: ,
parameters: { bar: true, baz: 12.4, qux: 'test test', quux: false },
node: {
type: 'html',
value: `
}
}
undefined
{
name: 'lint',
attributes: 'disable heading-style',
parameters: { disable: true, 'heading-style': true },
node: {
type: 'mdxFlowExpression',
value: '/ lint disable heading-style /'
}
}
This package exports the identifier [commentMarker][api-comment-marker].
There is no default export.
Parse a comment marker.
###### Parameters
* value (unknown)Node
— thing to parse, typically [][node]
###### Returns
Info ([Marker][api-marker]) when applicable or undefined.
Comment marker (TypeScript type).
###### Properties
* name (string)attributes
— name of marker
* (string)parameters
— value after name
* ([MarkerParameters][api-marker-parameters])node
— parsed attributes
* ([Node][node])
— reference to given node
Parameters (TypeScript type).
###### type
`ts`
type MarkerParameters = Record
Value (TypeScript type).
If it looks like a number (to JavaScript), it’s cast as number.
The strings true and false are turned into their correspondingtrue
booleans.
The empty string is also considered the boolean.
###### type
`ts`
type MarkerParameterValue = number | string | boolean
This package is fully typed with [TypeScript][].
This package exports the types [Marker][api-marker],MarkerParameters
[][api-marker-parameters], andMarkerParameterValue
[][api-marker-parameter-value]
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, mdast-comment-marker@^3,
compatible with Node.js 16.
Use of mdast-comment-marker does not involve [hast][], user content, or change
the tree, so there are no openings for [cross-site scripting (XSS)][xss]
attacks.
* mdast-zone
— change or replace a section marked by comments
See [contributing.md][contributing] in [syntax-tree/.github][health] forsupport.md`][support] for ways to get help.
ways to get started.
See [
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/syntax-tree/mdast-comment-marker/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/mdast-comment-marker/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-comment-marker.svg
[coverage]: https://codecov.io/github/syntax-tree/mdast-comment-marker
[downloads-badge]: https://img.shields.io/npm/dm/mdast-comment-marker.svg
[downloads]: https://www.npmjs.com/package/mdast-comment-marker
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-comment-marker
[size]: https://bundlejs.com/?q=mdast-comment-marker
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[mdast]: https://github.com/syntax-tree/mdast
[node]: https://github.com/syntax-tree/unist#node
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[hast]: https://github.com/syntax-tree/hast
[remark-lint]: https://github.com/remarkjs/remark-lint
[mdast-zone]: https://github.com/syntax-tree/mdast-zone
[api-comment-marker]: #commentmarkervalue
[api-marker]: #marker
[api-marker-parameters]: #markerparameters
[api-marker-parameter-value]: #markerparametervalue