-
This is more of a discussion around approaches toward handling multiple blank lines in sequence. I am definitely not knowledgeable on proper markdown syntax, and what may or may not be an ok thing to do, but I was hoping to get enlightened on an approach that seems to work toward adding support for multiple blank lines The example use case would be akin to things like discord and slack, where one can insert multiple newlines into a chat message and they are honored in the rendered output. A markdown string with multiple sequential newlines would be something like:
An approach I looked to using actually doesn't involve the MDAST, or even micromark extensions, but instead, ever so slightly modifying the input markdown string. Honestly, I've tried to understand why newlines get collapsed digging through the micromark code base, but Im afraid my understanding of what is going on there just isn't there yet. Anyways, so the idea I had was to just replace line breaks (LF, CR, CRLF) with a newline + non breaking space character. It seems with this, in conjunction with I would love some input into this approach, reasons why the approach may run into problems. And I would love to also get some feedback on if behavior like this would best be handled at the micromark level, MDAST level, or elsewhere. Anyways, here is a small demo of this. Using
Demo of approachhttps://codesandbox.io/s/create-react-app-forked-rfn632?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey! I believe this goes against the fundamental nature of markdown (and HTML), which marks up things to have meaning, and is not about WYSIWYG “drawing” of things. So yeah, you can regex find-and-replace line endings and add |
Beta Was this translation helpful? Give feedback.
-
Another alternative approach here using micromark's Totally get that the nodes rendered is no longer compliant with the commonmark spec, but if thats not a concern to peoples use case, is this ok to do? Or rather, is there an alarming issue that jumps out to you? Basically, the approach was to use an mdast extension to allow lineEndingBlanks to be represented in the final mdast. Demo of alternative approachhttps://codesandbox.io/s/create-react-app-forked-t6vzzj?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
Hey!
I believe this goes against the fundamental nature of markdown (and HTML), which marks up things to have meaning, and is not about WYSIWYG “drawing” of things.
Parsing markdown (and HTML), following standards, is also extremely involved: it’s super complex, there are all these edge cases that are handled by micromark/remark/etc.
If you just want to do something that discord or slack also do, and a bit different, then you’re not helped by markdown. You’re looking for something else. A couple of regexes. Something like https://github.com/developit/snarkdown maybe. There are probably more projects that slightly enhance comment boxes.
On the other hand, if you do want a standard that is …