{"id":29125780,"url":"https://github.com/syntax-tree/mdast-util-newline-to-break","last_synced_at":"2025-06-29T22:03:42.927Z","repository":{"id":159382206,"uuid":"634499199","full_name":"syntax-tree/mdast-util-newline-to-break","owner":"syntax-tree","description":"mdast utility to support hard breaks without needing spaces or escapes (turns enters into `\u003cbr\u003e`s).","archived":false,"fork":false,"pushed_at":"2023-07-08T15:06:28.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-23T08:38:47.000Z","etag":null,"topics":["break","linefeed","mdast","mdast-util","newline"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2023-04-30T10:25:26.000Z","updated_at":"2023-05-04T15:30:18.000Z","dependencies_parsed_at":"2023-09-07T02:02:33.549Z","dependency_job_id":null,"html_url":"https://github.com/syntax-tree/mdast-util-newline-to-break","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/mdast-util-newline-to-break","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-newline-to-break","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-newline-to-break/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-newline-to-break/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-newline-to-break/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/mdast-util-newline-to-break/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-newline-to-break/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261531270,"owners_count":23172766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["break","linefeed","mdast","mdast-util","newline"],"created_at":"2025-06-29T22:03:42.089Z","updated_at":"2025-06-29T22:03:42.838Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"readme":"# mdast-util-newline-to-break\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n**[mdast][]** utility to support hard breaks without needing spaces or\nescapes (turns enters into `\u003cbr\u003e`s).\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`newlineToBreak(tree)`](#newlinetobreaktree)\n*   [Syntax](#syntax)\n*   [Syntax tree](#syntax-tree)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a utility that takes an [mdast][] tree and turns soft line\nendings (enters) into hard breaks (`\u003cbr\u003e`s)\n\nThis package is used inside [remark-breaks][], which focusses on making it\neasier to transform content by abstracting these internals away.\n\n## When should I use this?\n\nThis plugin is useful if you want to display user content closer to how it was\nauthored, because when a user includes a line ending, it’ll show as such.\nGitHub does this in a few places (comments, issues, PRs, and releases), but it’s\nnot semantic according to HTML and not compliant to markdown.\nMarkdown already has two ways to include hard breaks, namely trailing spaces and\nescapes (note that `␠` represents a normal space):\n\n```markdown\nlorem␠␠\nipsum\n\nlorem\\\nipsum\n```\n\nBoth will turn into `\u003cbr\u003e`s.\nIf you control who authors content or can document how markdown works, it’s\nrecommended to use escapes instead.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-newline-to-break\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {newlineToBreak} from 'https://esm.sh/mdast-util-newline-to-break@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {newlineToBreak} from 'https://esm.sh/mdast-util-newline-to-break@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the following file, `example.md` (note: there are no spaces after\n`a`):\n\n```markdown\nThis is a\nparagraph.\n```\n\nAnd our module, `example.js`, looks as follows:\n\n```js\nimport fs from 'node:fs/promises'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {newlineToBreak} from 'mdast-util-newline-to-break'\nimport {toMarkdown} from 'mdast-util-to-markdown'\n\nconst doc = await fs.readFile('example.md')\nconst tree = fromMarkdown(doc)\n\nnewlineToBreak(tree)\n\nconsole.log(toMarkdown(tree))\n```\n\nNow, running `node example.js` yields:\n\n```md\nThis is a\\\nparagraph.\n```\n\n## API\n\nThis package exports the identifier [`newlineToBreak`][api-newline-to-break].\nThere is no default export.\n\n### `newlineToBreak(tree)`\n\nTurn normal line endings into hard breaks.\n\n#### Parameters\n\n*   `tree` ([`Node`][node])\n    — tree to modify\n\n## Syntax\n\nThis utility looks for markdown line endings (`\\r`, `\\n`, and `\\r\\n`).\n\n## Syntax tree\n\nThis utility adds mdast [`Break`][break] nodes to the syntax tree.\nThese are the same nodes that represent breaks with spaces or escapes.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nThere are no extra exported types.\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`mdast-util-newline-to-break@^2`, compatible with Node.js 16.\n\n## Security\n\nUse of `mdast-util-newline-to-break` does not involve **[hast][]** or user\ncontent so there are no openings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`remark-breaks`](https://github.com/remarkjs/remark-breaks)\n    — provide this utility as a [unified][] [remark][] plugin.\n*   [`remark-gfm`](https://github.com/remarkjs/remark-gfm)\n    — support GFM (autolink literals, footnotes, strikethrough, tables,\n    tasklists)\n*   [`remark-github`](https://github.com/remarkjs/remark-github)\n    — link references to commits, issues, and users, in the same way that\n    GitHub does\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-newline-to-break/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-newline-to-break/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-newline-to-break.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-newline-to-break\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-newline-to-break.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-util-newline-to-break\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=mdast-util-newline-to-break\n\n[size]: https://bundlejs.com/?q=mdast-util-newline-to-break\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/orgs/syntax-tree/discussions\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[remark-breaks]: https://github.com/remarkjs/remark-breaks\n\n[node]: https://github.com/syntax-tree/mdast#nodes\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[typescript]: https://www.typescriptlang.org\n\n[hast]: https://github.com/syntax-tree/hast\n\n[break]: https://github.com/syntax-tree/mdast#break\n\n[remark]: https://github.com/remarkjs/remark\n\n[api-newline-to-break]: #newlinetobreaktree\n\n[unified]: https://github.com/unifiedjs/unified\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-newline-to-break","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fmdast-util-newline-to-break","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-newline-to-break/lists"}