The `md-attr-parser` package, currently at stable version 1.3.0, provides a focused utility for extracting custom HTML attributes embedded within Markdown strings. It parses attribute blocks, typically enclosed in curly braces `{}` immediately following a Markdown element, to retrieve an ID, a list of classes, and arbitrary key-value pairs. The library outputs a structured object containing the parsed properties and the exact substring that was consumed. While there's no stated release cadence, as a specialized parser, updates are typically driven by bug fixes or syntax extensions rather than frequent iterations. Its key differentiators include the ability to start parsing from a specific offset within a string, and a configurable `defaultValue` option for attributes that are present but lack an explicit value, allowing for flexible integration into Markdown processing pipelines.
npm install md-attr-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic parsing of markdown attributes and advanced usage with an offset and custom default values for valueless keys.
If using ESM, try 'import parseAttr from "md-attr-parser"' or ensure your build system correctly transpiles CJS modules. For Node.js, consider checking if an 'exports' field is present in package.json or using dynamic import().
Ensure attribute strings adhere strictly to the documented syntax. For complex values or those containing special characters, consider pre-processing or post-processing the input/output to avoid conflicts.
Understand the distinction: 'editable' will use 'defaultValue', while 'editable=""' will result in 'editable: ""'. Adjust expectations or pre-process input if specific handling for empty string values is required.
If in CommonJS, use 'const parseAttr = require("md-attr-parser");'. If in ESM, try 'import parseAttr from "md-attr-parser";' as it's likely a default export.Verify the input string closely matches the documented syntax: '#id .class key=value'. Ensure no leading/trailing spaces within the attribute block unless intended, and proper quotes for values.
Provide the correct character offset for the beginning of the attribute string. For example, 'parseAttr(fullString, fullString.indexOf('{'));' if the attribute block is '{...}' and its position is unknown.No dependency data recorded yet.