I have a line that could be like
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged
Now, I have json that has a start and end line offset that I want to highlight. Now the logic I'm using is this:
$scope.highlightHTML = function(content, startoffset, endoffset) { var className = 'mark'; console.log(content.substring(startoffset, endoffset)); return content.replace(content.substring(startoffset, endoffset), '<span class="' + className + '">$&</span>'); }
So, here I am trying to extract from the last value of an array so that the offset will not be changed. Now there is one problem, and it seems to overlap. Now let's say
In this text, I highlighted Lorem Ipsum has been by adding some span class. Now, for the next interaction, if startoffset and endoffset have a string that is nothing but Ipsum has been the industry standard . Now there will be an overlap of the two, and then the selection overlaps. Thus, I cannot get the exact text, which is why the offsets change.
Now the other solution I applied was like
var length = '<span class="mark"></span>'.length: jsonDataArray.forEach(function(item, index) { responseData = $scope.highlightHTML(responseData, item.startOffset + (index * length), item.endOffset + (index * length), item.color); }); $rootScope.data.htmlDocument = responseData.replace(/\n/g, "</br>");
But here is also the same problem, as if some part of one thing is present in another, it creates some problems. Can someone help me with this?