Fixed bug with multiple matches in same text node

The previous change introduced a bug where there would be an error
when replacing the child. The reason is if there are multiple matches
in the same text node, the child would try to be replaced multiple
times, obviously failing. Instead, we replace only on the first time,
and after that append after the last mark node