Rewrite marker insertion algorithm to fix issues related to space & newlines.