diff --git a/src/Sanitizer.php b/src/Sanitizer.php index 58c8111..abe3aaf 100644 --- a/src/Sanitizer.php +++ b/src/Sanitizer.php @@ -231,6 +231,17 @@ public function sanitize($dirty) $this->resetAfter(); + // extract and merge invisible tags + $clean = preg_replace_callback('/]*>(?.+?)<\/defs>|]*>(?.+?)<\/style>/s',function(array $result): string + { + if (isset($result['defs'])) $this->defs[] = $result['defs']; + if (isset($result['styl'])) $this->styl[] = $result['styl']; + return '';// remove finding + },$clean); + + if (!empty($this->defs)) $clean = preg_replace('/(]*>)/','$1' .implode('',$this->defs).''); + if (!empty($this->styl)) $clean = preg_replace('/(]*>)/','$1'); + // Remove any extra whitespaces when minifying if ($this->minifyXML) { $clean = preg_replace('/\s+/', ' ', $clean);