In order to only allow certain tags, you need to parse the HTML into tags, attributes, then remove the unwanted ones and reassemble the HTML again.
This is nontrivial.
To make matters worse, there are some attributes that you probably want to allow, that need their values filtering against certain patterns (blacklist or whitelist).
As I said before, it's nontrivial.
Mark