Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Simplifies implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jensscherbl committed Feb 3, 2023
1 parent ace602c commit deb3419
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
37 changes: 34 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
<?php declare(strict_types=1);
<?php
/**
* @noinspection PhpUnhandledExceptionInspection
*/
declare(strict_types=1);

namespace Kenshō\XHTML;

use DOMDocument;
use Kirby\Cms\App;

const XML = [
'htm',
'html',
'rss',
'xht',
'xhtml',
'xml',
'xsl',
];
const XHTML = [
'htm',
'html',
'xht',
'xhtml',
];
App::plugin('kensho/xhtml', [
'hooks' => [
/**
* 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;
},
Expand Down
38 changes: 0 additions & 38 deletions src/XMLProcessor.php

This file was deleted.

0 comments on commit deb3419

Please sign in to comment.