I'm using mark.js's markRanges() method to highlight ranges with a start position and length, however, it's not respecting HTML elements such as line break elements. The documentation notes that start positions must be specified including whitespace characters.
For example, the following HTML:
<div contenteditable="true" id="text">hi.<br><br>I'm quite well.<br></div>
When marking a range with a start 15 and length 5:
var elem = document.getElementById('text');
var instance = new Mark(elem);
var options = {
"element": "mark"
};
instance.markRanges([{
start: 15,
length: 5
}], options);
The word "quite" should be highlighted, however, instead it will highlight the last two letters of the world we"ll", as the markRanges() method is not counting the characters of the two proceeding <br>
line break elements.
My fiddle https://jsfiddle.net/93swuqa6/
tags, see https://github.com/julmot/mark.js/issues/127 – dude Sep 28 '20 at 07:19