mdast-comment-marker

mdast utility to parse a comment marker

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-comment-marker
902.1.0a year ago7 years agoMinified + gzip package size for mdast-comment-marker in KB

Readme

mdast-comment-marker
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
mdastmdast utility to parse comment markers.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install mdast-comment-marker
## Use

```js
import {commentMarker} from 'mdast-comment-marker'

console.log(commentMarker({
  type: 'html',
  value: '<!--foo-->'
}));

console.log(commentMarker({
  type: 'html',
  value: '<!--foo bar baz=12.4 qux="test test" quux=\'false\'-->'
}));

console.log(commentMarker({
  type: 'html',
  value: '<!doctype html>'
}));

// Also supports MDX@2 expressions:
console.log(commentMarker({
  type: 'mdxFlowExpression',
  value: '/* lint disable heading-style */'
}));

Yields:
{
  name: 'foo',
  attributes: '',
  parameters: {},
  node: { type: 'html', value: '<!--foo-->' }
}
{
  name: 'foo',
  attributes: `bar baz=12.4 qux="test test" quux='false'`,
  parameters: { bar: true, baz: 12.4, qux: 'test test', quux: false },
  node: {
    type: 'html',
    value: `<!--foo bar baz=12.4 qux="test test" quux='false'-->`
  }
}
null
{
  name: 'lint',
  attributes: 'disable heading-style',
  parameters: { disable: true, 'heading-style': true },
  node: {
    type: 'mdxFlowExpression',
    value: '/* lint disable heading-style */'
  }
}

API

This package exports the following identifiers: commentMarker. There is no default export.

commentMarker(node)

Parse a comment marker.
Parameters
Returns
Marker?marker — Information, when applicable.

Marker

A comment marker.
Properties
  • name (string) — Name of marker
  • attributes (string) — Value after name
  • parameters (Object) — Parsed attributes, tries to convert
values to numbers and booleans when possible
  • node (Nodenode) — Reference to given node

Security

Use of mdast-comment-marker does not involve hasthast, user content, or change the tree, so there are no openings for cross-site scripting (XSS)xss attacks.

Related

— treat HTML comments as ranges or markers

Contribute

See contributing.md in syntax-tree/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor