mdast-util-newline-to-break is a utility for the unified ecosystem that transforms soft line endings (simple newlines) in an mdast syntax tree into hard break (<br>) nodes. This is particularly useful for rendering user-authored content where line breaks should visually translate to actual line breaks, mimicking GitHub's behavior in comments or issues. The current stable version is 2.0.0. As part of the unified collective, it maintains compatibility with actively supported Node.js versions, with major releases typically coinciding with Node.js LTS updates. Unlike standard Markdown, which requires two trailing spaces or a backslash for a hard break, this utility provides a more direct conversion. It is often used internally by higher-level plugins like `remark-breaks`.
npm install mdast-util-newline-to-breakVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a Markdown string, apply `newlineToBreak` to its mdast tree, and then convert it back to Markdown to see the effect of hard breaks.
Upgrade your Node.js environment to version 16 or newer. If you cannot upgrade, remain on `mdast-util-newline-to-break@^1`.
Refactor your imports to use ESM `import` statements. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Use a utility like `unist-util-deepcopy` or structured cloning (`structuredClone(tree)`) if available in your environment, to create a copy of the tree before modification.
Document this behavior to users if they are authoring content, or consider using standard Markdown practices (trailing spaces or backslashes) instead for strict CommonMark compliance.
Change `const { newlineToBreak } = require('mdast-util-newline-to-break');` to `import { newlineToBreak } from 'mdast-util-newline-to-break';` and ensure your project uses ESM.Ensure you are using a named import for `newlineToBreak`: `import { newlineToBreak } from 'mdast-util-newline-to-break';`No dependency data recorded yet.