-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move transformer into mdast-util-breaks
#9
Comments
Sounds good to me, thanks @remcohaszing! |
Yeah, sure. Why not I’m not sure what I think |
It works if you read “break” as a verb. Anyway, I like What license should I use? Since it’s going to be mostly based on this repo, copy the license as-is? |
That could be an explanation, but then I think that’s a bit weird, wouldn’t you break the lines instead?
Yep, reuse the one seems fine. I think you could also go with: /**
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
*/
/**
* @typedef {Content | Root} Node
*/
import {findAndReplace} from 'mdast-util-find-and-replace'
/**
* Turn normal line endings into hard breaks.
*
* @param {Node} tree
* Tree to change.
* @returns {void}
* Nothing.
*/
export function newlineToBreak(tree) {
findAndReplace(tree, /\r?\n|\r/g, replace)
}
/**
* Replace line endings.
*
* @type {ReplaceFunction}
* @param {string} value
*/
function replace(value) {
return [{type: 'break'}, {type: 'text', value}]
} This is what I have locally now in AFAIK it is mostly equivalent: because line endings can never occur at the start or end of a paragraph, or next to each other (blank lines). Though this Looking at the current algo, it actually drops all positional info on text nodes? 🤔 |
The implementation is based on `remark-break`. It was copied, then modified. The following modifications have been made: - The implementation was moved from `index.js` to `lib/index.js`. - The remark plugin was replaced with the function `newlineToBreak`. - The implementation was based on remarkjs/remark-breaks#9 (comment). - Tests are based on markdown output, not html output. This uncovered a small bug in the implementation linked above that has been fixed. - Tests are not based on a unified pipeline. - `tape` was replaced with `node:test`. - Each test fixture now has its own test case. This allows test filtering and inspecting multiple failed tests. - Dependencies were updated. - Support was dropped for Node.js < 16. - The readme was updated accordingly.
Initial checklist
Problem
The transformer can work on the AST without unified. It may be useful to use this as a plain function.
Solution
Move the transformer into a new package
mdast-util-breaks
. This package would be part of syntax-tree.Alternatives
I chose the name to match the name
remark-breaks
, but it may make sense to use something more verbose, e.g.:mdast-util-break-newlines
.The text was updated successfully, but these errors were encountered: