JSFiddle - React, Tailwind, and code Playground
HTML
<!--
StackOverflow: http://stackoverflow.com/questions/11232795/how-can-i-determine-the-positions-of-new-lines-in-the-text-of-an-html-element
-->
<div id="text"><!-- slipsum.com -->
You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder. After the avalanche, it took us a week to climb out. Now, I don't know exactly when we turned on each other, but I know that seven of us survived the slide... and only five made it out. Now we took an oath, that I'm breaking now. We said we'd say it was the snow that killed the other two, but it wasn't. Nature is lethal but it doesn't hold a candle to man.
</div>
CSS
#text {
width: 300px;
}
JavaScript
// textNodes don't have a position, so just wrap them in spans
// http://stackoverflow.com/questions/396649/retrieving-dom-textnode-position
// sorry, wasn't intrigued by the text-selection idea...
var $text = $('#text'),
breaks = [],
top;
// wrap words (\w+) and punctuation (\S+) [well, non-word and non-space]
// in <spans> we can easily identify
$text.html($text.text().replace(/(\w+|\S+)/g, '<span>$1</span>'));
$text.children().each(function() {
var $this = $(this),
_top = $this.position().top;
if (top === undefined) {
top = _top;
} else if (top < _top) {
top = _top;
// moved a row down
breaks.push($this.prev());
$this.prev().css('color', 'red');
}
});
console.log(breaks);