Don't use replace to swap in code with dollars in it, fix #587.