I am new to `angular js`and `javascript`. Here, I have document or text file which is lets say like ->

```
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's 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, In this file I want to highlight the part 

```
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and

```

So, For highlighting this text from back end I get the offsets which I mean is the startoffset and endoffset of that string.

So, Then I use the following method to highlight the text .

```
$scope.highlightHTML(responseData, startOffset, endOffset);
$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, It replaces this text with span tag. Now, Because of this In my array where I have more than 1 elements which I need to highlight in this text.
Because of this the offsets which I get from back end will get changed .So for this I used the following logic ->

```
var length = '<span class="mark"></span>'.length:
jsonDataArray.forEach(function(item, index) {
    responseData = $scope.highlightHTML(responseData, item.startOffset + (index * length), item.endOffset + (index * length));
});

```

But Here is the main problem .

Now lets say Now I want to highlight the text `1500s` , Now here When it comes to find the offset of this string then It will not match with the new multiply logic . Because this `1500's` part is present previously highlighted string. 

Previous string will be 

```
<span class="mark">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and</span>

```

Now I want to highlight the `1500s`. Then if I multiply then it will not take the perfect offsets , so will not get the string to highlight. 

So, How can I resolve this issue ? Can any one help me with this ?