Best way to filter harmful code in Html editor

Check my reply here: XSS vulnerability in HTML Editor - #2 by korchev