From deb341904d7da2de940204a426d3f35aed4743b9 Mon Sep 17 00:00:00 2001 From: Jens Scherbl Date: Fri, 3 Feb 2023 22:28:49 +0100 Subject: [PATCH] Simplifies implementation --- composer.json | 2 +- index.php | 37 ++++++++++++++++++++++++++++++++++--- src/XMLProcessor.php | 38 -------------------------------------- 3 files changed, 35 insertions(+), 42 deletions(-) delete mode 100755 src/XMLProcessor.php diff --git a/composer.json b/composer.json index 479e229..7127efe 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "kenshodigital/kirby-xhtml", "description": "Ensures well-formed XML and XHTML output for Kirby templates.", "type": "kirby-plugin", - "version": "1.0.1", + "version": "1.0.0", "homepage": "https://github.com/kenshodigital/kirby-xhtml", "license": "MIT", "authors": diff --git a/index.php b/index.php index e573993..2781796 100755 --- a/index.php +++ b/index.php @@ -1,15 +1,46 @@ - [ + /** + * Ensures well-formed XML and XHTML + * output and strips whitespace between + * nodes. + */ 'page.render:after' => function (string $contentType, array $data, string $html): string { - if (\in_array($contentType, XMLProcessor::TYPES)) { - $html = (new XMLProcessor(new DOMDocument))->process($html); + if (\in_array($contentType, XML)) { + $document = new DOMDocument; + $document->preserveWhiteSpace = FALSE; + $document->loadXML($html); + + if (\in_array($contentType, XHTML)) { + App::instance()->response()->type('application/xhtml+xml'); + } + return $document->saveXML(); } return $html; }, diff --git a/src/XMLProcessor.php b/src/XMLProcessor.php deleted file mode 100755 index 54bb613..0000000 --- a/src/XMLProcessor.php +++ /dev/null @@ -1,38 +0,0 @@ -'; - - public function __construct( - private readonly DOMDocument $document - ) { - $this->document->preserveWhiteSpace = FALSE; - } - - public function process(string $output): string - { - $this->document->loadXML(self::XML_DECLARATION . $output); - - return $this->document->saveXML(); - } -}