Clear refs and anchors when clearing text. Fixes #2250.
Merge pull request #2251 from matham/refs-markup

Clear refs and anchors when clearing text. Fixes #2250.