mdast Comment Marker Parser

3.0.0 · active · verified Sun Apr 19

mdast-comment-marker is a utility for parsing structured markers from comments within an mdast (Markdown Abstract Syntax Tree) document. It's currently at version 3.0.0 and follows a release cadence tied to major ecosystem updates like Node.js versions and mdast/MDX specifications. This package differentiates itself by providing a robust way to extract 'processing instructions' or metadata embedded in HTML or MDX comments, such as `<!-- lint disable -->` or `/* zone foo */`. It handles various parameter types including booleans, numbers, and strings, making it suitable for tools like remark-lint or mdast-zone, which utilize these markers for configuration or content manipulation. It is ESM-only and requires Node.js 16 or later.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `commentMarker` to parse different types of comment nodes (HTML and MDX) into structured marker objects, including handling various parameter types.

import { commentMarker } from 'mdast-comment-marker';

// Example 1: Basic HTML comment marker
console.log(commentMarker({ type: 'html', value: '<!--foo-->' }));

// Example 2: HTML comment marker with various parameters
console.log(commentMarker({
  type: 'html',
  value: '<!--foo bar baz=12.4 qux="test test" quux=\'false\'-->'
}));

// Example 3: MDX Flow Expression comment marker
console.log(commentMarker({
  type: 'mdxFlowExpression',
  value: '/* lint disable heading-style */'
}));

// Example 4: A comment that does not parse as a marker
console.log(commentMarker({ type: 'html', value: '<!doctype html>' }));

view raw JSON →