htmlpurifiercsstidy

what will it take to allow media queries through HTMLPurifier + CSStidy


what would it take to allow media queries through HTMLPurifier + CSStidy?

In other words, I am using these libraries:

require_once 'inc_php_classes/htmlpurifier-4_4_0/library/HTMLPurifier.auto.php';
require_once 'inc_php_classes/csstidy-1_3/class.csstidy.php';

...to sanitize admin-user input before I save it to database.. for populating an external style sheet ... and so it happens that any input media queries are getting munged.. e.g. this:

@media only screen and (min-width: 600px) and (max-width: 939px) {

becomes

@media only screen and min-width 600px and max-width 939px {

..which breaks the media query, at least in Chrome 18/Mac.

The form/input is used for creating custom style sheets for trusted admin users.. and they need media queries.. but even though they are trusted, I do not want to just drop use of CSStidy.. because of the off chance an admin goes AWOL, not to mention I want to clean their newbie CSS errors.


Solution

  • Not sure, it's definitely not supported by vanilla HTML Purifier. It is reasonably plausible that CSSTidy does parse media selectors properly, so it's just a matter of teaching HTML Purifire not to strip them out.