unified

Project: syntax-tree/mdast-comment-marker

Package: mdast-comment-marker@2.0.0

  1. Dependents: 6
  2. mdast utility to parse a comment marker
  1. util 143
  2. utility 139
  3. unist 127
  4. mdast 85
  5. mdast-util 30
  6. marker 13
  7. comment 8

mdast-comment-marker

Build Coverage Downloads Size Sponsors Backers Chat

mdast 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:

npm install mdast-comment-marker

Use

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? — Information, when applicable.

Marker

A comment marker.

Properties

Security

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) attacks.

Contribute

See contributing.md in syntax-tree/.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.

License

MIT © Titus Wormer