HtmlRuleSanitizer icon indicating copy to clipboard operation
HtmlRuleSanitizer copied to clipboard

sanitizer.Tag("p").RemoveEmpty(); <p> </p> results in <p>&#160;</p>

Open mistyn8 opened this issue 6 years ago • 3 comments

sanitizer.Tag("p").RemoveEmpty(); <p> </p> results in <p>&#160;</p>

Could RemoveEmpty() be extended to cover RemoveEmptyOrWhitespace() ??

mistyn8 avatar Jul 04 '19 11:07 mistyn8

This is a valid request, but unfortunately I believe this is currently not so easy to implement. One method would be to implement this handling in a dedicated virtual method, which can be overridden.

Would you want this rule to be able to treat non breaking spaces separately? In other words should an element which includes only white space, but of which at least part of the white space are non breaking spaces, also be removed?

cakkermans avatar Oct 27 '19 21:10 cakkermans

Maybe follow String.IsNullOrEmpty and String.IsNullOrWhiteSpace ??

mistyn8 avatar Nov 07 '19 16:11 mistyn8

A solution based on Char.IsWhiteSpace(), which backs String.IsNulOrWhiteSpace, might work if it is an option. I however found some detailed documentation at MDN https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace which suggest things are not that straight forward.

cakkermans avatar Aug 13 '21 14:08 cakkermans