public static function cleanHTML($html, $filter_set = self::S_MEDIA){

		$filters = self::getFilters($filter_set);

		// Pre-processing

		$html = preg_replace('/[\s]+/', ' ', $html);
		$html = str_replace('> <', '><', $html);

		$html = preg_replace('/(<br>)+/', '<br>', $html);
		$html = str_replace(['<br></', '><br>'], ['</', '>'], $html);

		// Clean HTML

		libxml_clear_errors();

		$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
		$Document = new \DOMDocument();
		@$Document->loadHTML($html);

		if(empty($Document)){

			$libXMLError = libxml_get_last_error();
			$xml_error = '';

			if($libXMLError instanceof \LibXMLError){

				$xml_error = ", libXML reports: {$libXMLError->message}";
			}

			throw new HTMLException('Invalid HTML provided' . $xml_error);
		}

		$html = self::_cleanHTML($Document, $filters);

		// Post-processing

		$html = preg_replace('/[\s]+/', ' ', $html);
		$html = str_replace('> <', '><', $html);

		$html = preg_replace('/(<br>)+/', '<br>', $html);
		$html = str_replace(['<br></', '><br>'], ['</', '>'], $html);

		$html = Sanitize::replaceHttpsUrls($html);

		$html = trim($html);

		/**
		 * Sometimes we just have some leftover attributes like an br. That the
		 * text is not considered empty. But actually there is no visual content.
		 *
		 * Is the text without tags is empty we just return an empty string.
		 * One exception are images cause they do not contain an textual value.
		 */

		if($html === '<br>'){

			$html = '';
		}

		return $html;
	}