Fixed bug with adding mark back into parent

Previously we removed the matched text node and appended the new mark
node to the end of the parent. The issue with this is there might be a
non-text node adjacent to the parent, so the mark would be appended
after this. Instead, we replace the matched text node, using
insertBefore to handle the text before and after the matched text