mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
60 lines
1.0 KiB
PHP
60 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Jingga
|
|
*
|
|
* PHP Version 8.2
|
|
*
|
|
* @package phpOMS\Utils\Formatter
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Utils\Formatter;
|
|
|
|
/**
|
|
* Html code formatter
|
|
*
|
|
* @package phpOMS\Utils\Formatter
|
|
* @license OMS License 2.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
*/
|
|
final class HtmlFormatter
|
|
{
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
private function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Format html code
|
|
*
|
|
* @param string $text Html code
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public static function format(string $text) : string
|
|
{
|
|
$dom = new \DOMDocument();
|
|
|
|
$dom->loadHTML($text);
|
|
|
|
$dom->preserveWhiteSpace = false;
|
|
$dom->formatOutput = true;
|
|
|
|
$formatted = $dom->saveXML($dom->documentElement);
|
|
|
|
return $formatted === false ? '' : $formatted;
|
|
}
|
|
}
|