Move reference patching into HTML translator