Generic function to replace special HTML pseudo-tags refs #2652