{"library":"mdast-util-newline-to-break","title":"Convert Newlines to Hard Breaks in mdast","description":"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`.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mdast-util-newline-to-break"],"cli":null},"imports":["import { newlineToBreak } from 'mdast-util-newline-to-break';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import fs from 'node:fs/promises';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { toMarkdown } from 'mdast-util-to-markdown';\nimport { newlineToBreak } from 'mdast-util-newline-to-break';\n\nasync function processMarkdown() {\n  // Assume example.md contains:\n  // This is a\n  // paragraph.\n  const doc = 'This is a\\nparagraph.'; // Simulate reading a file\n  const tree = fromMarkdown(doc);\n\n  newlineToBreak(tree);\n\n  // The output will show 'This is a\\nparagraph.' as 'This is a\\\n  // paragraph.' after conversion to markdown, representing a hard break.\n  console.log(toMarkdown(tree));\n}\n\nprocessMarkdown().catch(console.error);","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}