Proof of Brain.Blog Change Ahead
My intention is to add code that would make full names and numbers where spaces are used as thousands separators as unbreakable for line breaking. For example, if we take this name "Adam B. Levine" or "Andreas Anantonopolus", the name would not break according to how you resize your browser window.
I have come across some complications on implementing this. Changing the body text while typing destroys the normal flow of typing, so it should happen instead when the submit button is pressed or when the user clicks away from the text.
Here is an example of a long number using digit spaces: 16 777 216.
So my plan is to do automatic substitution from normal breaking space characters for non-breaking space characters when a part of the text looks like a name. I'd like to get rid of breaking inside book titles. Like Alice In Wonderland or *20,000 Leagues Under the Sea". The code has to be extended to recognize 20,000 and lowercase words like "the" in the title.
Perhaps some of you would like to weigh in on the downsides of doing this. Perhaps @ecency has some ideas.
Basically the code is:
editBody = (text: string): string => {
return text
// Keep first names, last names and letters after on the same line.
.replace(/([A-Z][a-z]+)[\u00a0 ]([A-Z][a-z]+)[\u00a0 ]([A-Z][a-z]+)[\u00a0 ]([A-Z][A-Za-z.]+)/,'$1\u00a0$2\u00a0$3\u00a0$4')
.replace(/([A-Z][a-z]+)[\u00a0 ]([A-Z][a-z]+)[\u00a0 ]([A-Z][A-Za-z.]+)/,'$1\u00a0$2\u00a0$3')
.replace(/([A-Z][a-z]+)[\u00a0 ]([A-Z][A.Z.a-z]+)/,'$1\u00a0$2')
// keep numbers with spaces together on the same line
.replace(/(\d+) (\d+) (\d+) (\d+)/, '$1\u2007$2\u2007$3\u2007$4')
.replace(/(\d+) (\d+) (\d+)/, '$1\u2007$2\u2007$3')
.replace(/(\d+) (\d+)/, '$1\u2007$2')
}
🍀🍀🍀 🧠 @leprechaun
Posted with proof of brain.... Prove your brain now.🧠🧠🧠