mdast-util-to-nlcst is a utility in the unifiedjs ecosystem that transforms an mdast (markdown abstract syntax tree) into an nlcst (natural language concrete syntax tree). Currently at stable version 7.0.1, the package follows a semver release cadence with notable breaking changes often accompanying major version bumps. Its core function is to allow inspection of the natural language content within markdown documents by providing a structured NLCST representation. Unlike other utilities like `mdast-util-to-hast` which converts markdown to HTML, this package focuses specifically on language processing. It is frequently used in conjunction with natural language parsers like `parse-english` or `parse-latin` and is wrapped by the `remark-retext` plugin for a higher-level abstraction. A key limitation is that it does not provide functionality to apply changes from the NLCST back into the original mdast tree.
npm install mdast-util-to-nlcstVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting markdown content from a VFile into an mdast tree, then transforming it into an nlcst tree using `ParseEnglish`, and inspecting the resulting natural language AST.
Ensure your project's `package.json` correctly resolves `mdast-util-to-nlcst` imports (e.g., in bundlers) and update all related `@types` and `vfile` dependencies to their latest compatible versions. Avoid using private APIs.
Upgrade your Node.js environment to version 14.14 or newer. Update your natural language parsers (e.g., `parse-english`, `parse-latin`) to their latest versions to match the new API.
Migrate your project to use ES modules (`import`/`export`) or use a bundler that transpiles ESM to CommonJS if strictly necessary.
Ensure that the mdast tree is generated from a source that provides positional data (e.g., `mdast-util-from-markdown` with a `VFile`) and always pass a valid `VFile` object as the second argument to `toNlcst`.
Understand that `mdast-util-to-nlcst` is a one-way transformation. If you need to modify markdown based on natural language analysis, you will need to implement a separate process to map nlcst changes back to mdast or work directly on the mdast tree using other utilities.
Change `const { toNlcst } = require('mdast-util-to-nlcst')` to `import { toNlcst } from 'mdast-util-to-nlcst'` and ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json` or using a bundler).Ensure the parser is imported using named imports: `import { ParseEnglish } from 'parse-english'` (not `import ParseEnglish from 'parse-english'`).Upgrade your Node.js environment to version 14.14 or higher. The unified collective generally maintains compatibility with active LTS Node.js versions.
Ensure your mdast tree is generated by a parser that includes positional data (like `mdast-util-from-markdown`). Always provide a valid `VFile` object as the `file` argument, which typically holds the original source content and its associated positional data.