fix wrong rehighlighting issues

applying copyState properly as well as moving some html-speccific highlighting
portion out of ruby block