Skip to content
Snippets Groups Projects
Commit b3bb64c3 authored by Jared Hancock's avatar Jared Hancock
Browse files

html: Remove duplicate style properties

Also use single quotes instead of double quotes in style attributes which
do not require escaping to "
parent 2a0ada1d
No related branches found
No related tags found
No related merge requests found
......@@ -178,13 +178,25 @@ class Format {
// Clean browser-specific style attributes
if (isset($attributes['style'])) {
$styles = preg_split('/;\s*/S', html_entity_decode($attributes['style']));
$props = array();
foreach ($styles as $i=>&$s) {
@list($prop, $val) = explode(':', $s);
if (isset($props[$prop])) {
unset($styles[$i]);
continue;
}
$props[$prop] = true;
// Remove unset or browser-specific style rules
if (!$val || !$prop || $prop[0] == '-' || substr($prop, 0, 4) == 'mso-')
unset($styles[$i]);
// Remove quotes of properties without enclosed space
if (!strpos($val, ' '))
$s = str_replace('"','', $s);
$val = str_replace('"','', $val);
else
$val = str_replace('"',"'", $val);
$s = "$prop:".trim($val);
}
unset($s);
if ($styles)
$attributes['style'] = Format::htmlencode(implode(';', $styles));
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment