site/node_modules/mdast-util-newline-to-break/lib/index.js

28 lines
534 B
JavaScript
Raw Permalink Normal View History

2024-10-14 06:09:33 +00:00
/**
* @typedef {import('mdast').Nodes} Nodes
* @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
*/
import {findAndReplace} from 'mdast-util-find-and-replace'
/**
* Turn normal line endings into hard breaks.
*
* @param {Nodes} tree
* Tree to change.
* @returns {undefined}
* Nothing.
*/
export function newlineToBreak(tree) {
findAndReplace(tree, [/\r?\n|\r/g, replace])
}
/**
* Replace line endings.
*
* @type {ReplaceFunction}
*/
function replace() {
return {type: 'break'}
}