Skip to content

Commit

Permalink
Trim whitespaces in HTMLSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Apr 3, 2024
1 parent 7290a69 commit 1fbef29
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/serializer/HTMLSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Templado\Engine;

use function trim;
use const LIBXML_NOEMPTYTAG;
use function assert;
use DOMDocument;
Expand All @@ -19,7 +20,9 @@
use XMLWriter;

class HTMLSerializer implements Serializer {

private const HTMLNS = 'http://www.w3.org/1999/xhtml';

private bool $stripRDFaFlag = false;

private bool $keepXMLHeaderFlag = false;
Expand Down Expand Up @@ -117,10 +120,14 @@ private function serializeToCleanedString(DOMDocument $document): string {
private function walk(XMLWriter $writer, DOMNode $node, array $knownPrefixes): void {
$dom = $node->ownerDocument;


if (!$node instanceof DOMElement) {
$writer->writeRaw(
$dom->saveXML($node)
);
$content = trim($dom->saveXML($node));
if ($content === '') {
return;
}

$writer->writeRaw($content);

return;
}
Expand Down

0 comments on commit 1fbef29

Please sign in to comment.