Giter Club home page Giter Club logo

Comments (4)

ChristianMurphy avatar ChristianMurphy commented on May 24, 2024

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.

wooorm avatar wooorm commented on May 24, 2024

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.

remcohaszing avatar remcohaszing commented on May 24, 2024

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.

wooorm avatar wooorm commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.