Comments (4)
Sounds good to me, thanks @remcohaszing!
the more verbose name mdast-util-break-newlines
sounds better to me, but interested to hear others thoughts.
from remark-breaks.
Yeah, sure.
Why not mdast-util-hard-break
? mdast-util-automatic-break
? mdast-util-auto-hard-break
? mdast-util-newline-to-break
? (optionally with s
suffix)
I’m not sure what break-newlines
means, it feels “inverted”.
I think mdast-util-newline-to-break
is my preference.
from remark-breaks.
I’m not sure what
break-newlines
means, it feels “inverted”.
It works if you read “break” as a verb.
Anyway, I like mdast-util-newline-to-break
too. I’ll go with that. I’ll get to it later this week.
What license should I use? Since it’s going to be mostly based on this repo, copy the license as-is?
from remark-breaks.
That could be an explanation, but then I think that’s a bit weird, wouldn’t you break the lines instead? break-lines
?
What license should I use?
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 rehype-github-*
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 findAndReplace
method would split the line endings from the next text? Maybe findAndReplace
should be updates to merge initial/final text node results?
Looking at the current algo, it actually drops all positional info on text nodes? 🤔
from remark-breaks.
Related Issues (7)
- Flag for not collapsing new lines / blank lines / newlines / blanklines HOT 4
- unist-util-visit missing in dependencies HOT 1
- Doesn't cover headings. HOT 5
- Breaks are not applied inside a table cell HOT 1
- How to prevent the break under definition lists HOT 6
- Heading line breaks only render using alternative syntax HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remark-breaks.