Search highlighting fixed.

After some debugging, have figured out that the issue with the
highlighting was that .replace does not mutate the string after each
replacement. Whereas when the inverse while function was iterating
backwards it was updating the string with each iteration. So have added
an offset counter when initially doing the replacements on the string.
Unfortunately this was not all that was wrong so it didn't immediately
seem to fix the issue. But with a few other bugfixes everything seems to
be working well.

That is with the exception of one outstanding issue when a word is
broken up by some HTML eg. wo<span>rd</span>. If someone were to search
for "wor" the resulting highlighted string would be <span
class="search-highlight">wo<span>r</span>d</span> which is not correct.
The only way I can see of fixing this is to wrap each matched letter
individually. Which will result in heavier HTML but should fix the
issue.