{"library":"mdast-util-heading-style","title":"mdast Heading Style Utility","description":"mdast-util-heading-style is a focused utility designed to determine the style of a heading within an `mdast` (Markdown Abstract Syntax Tree) node. It identifies if a heading was authored using ATX (hashes, e.g., `## Heading`), ATX-closed (e.g., `## Heading ##`), or Setext (underline, e.g., `Heading\\n===`) Markdown syntax. The package is currently at version 3.0.0 and operates within the broader `unified` ecosystem, often leveraged by linting tools like `remark-lint`. Its release cadence is tied to Node.js LTS versions, with major releases typically dropping support for unmaintained Node.js versions. A key differentiator is its precise, narrow scope: providing just the heading style information, rather than modifying or transforming the AST, making it a reliable building block for more complex Markdown processing pipelines. It is an ES module (ESM) only.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mdast-util-heading-style"],"cli":null},"imports":["import { headingStyle } from 'mdast-util-heading-style'","import type { Style } from 'mdast-util-heading-style'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { unified } from 'unified';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { headingStyle } from 'mdast-util-heading-style';\nimport type { Heading } from 'mdast'; // Assuming @types/mdast is installed for type safety\n\nconst parser = unified().use(fromMarkdown);\n\n// Example 1: ATX heading\nconst atxAst = parser.parse('# ATX');\nconst atxNode = atxAst.children[0] as Heading;\nconsole.log(`'# ATX' style: ${headingStyle(atxNode)}`);\n// Expected output: '# ATX' style: atx\n\n// Example 2: ATX closed heading\nconst atxClosedAst = parser.parse('# ATX #\\n');\nconst atxClosedNode = atxClosedAst.children[0] as Heading;\nconsole.log(`'# ATX #' style: ${headingStyle(atxClosedNode)}`);\n// Expected output: '# ATX #' style: atx-closed\n\n// Example 3: Setext heading\nconst setextAst = parser.parse('Setext\\n===');\nconst setextNode = setextAst.children[0] as Heading;\nconsole.log(`'Setext\\n===' style: ${headingStyle(setextNode)}`);\n// Expected output: 'Setext\\n===' style: setext\n\n// Example 4: ATX heading with depth 3, potentially ambiguous for setext\nconst depth3Ast = parser.parse('### Another ATX');\nconst depth3Node = depth3Ast.children[0] as Heading;\n// By default, it might return undefined if it's not clearly ATX or Setext\nconsole.log(`'### Another ATX' style (default): ${headingStyle(depth3Node)}`);\n// Expected output: '### Another ATX' style (default): undefined\n// Can be considered 'setext' if relative style is specified\nconsole.log(`'### Another ATX' style (relative setext): ${headingStyle(depth3Node, 'setext')}`);\n// Expected output: '### Another ATX' style (relative setext): setext","lang":"typescript","description":"Demonstrates parsing various Markdown heading styles into an `mdast` AST and then using `headingStyle` to determine their type, including how to handle `undefined` results and the `relative` style option.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}