From bce08d6b43290398af942886a1f2c333838f4a03 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 8 May 2023 12:00:04 +0200 Subject: [PATCH] Make the normalizer reusable by passing in the `\DOMXPath` for `normalize()` --- .../node/HtmlOutputNodeNormalizer.class.php | 18 +++++++----------- .../node/HtmlOutputNodeProcessor.class.php | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php index 4bf2fdafab..85dc429555 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php @@ -14,26 +14,22 @@ use wcf\util\DOMUtil; */ final class HtmlOutputNodeNormalizer { - public function __construct(private readonly \DOMXPath $xpath) + public function normalize(\DOMXPath $xpath): void { - } - - public function normalize(): void - { - $this->normalizeBr(); + $this->normalizeBr($xpath); - $candidates = $this->getPossibleSpacerParagraphs(); + $candidates = $this->getPossibleSpacerParagraphs($xpath); $this->reduceSpacerParagraphs($candidates); } /** * @return list<\DOMElement> */ - private function getPossibleSpacerParagraphs(): array + private function getPossibleSpacerParagraphs(\DOMXpath $xpath): array { $paragraphs = []; - foreach ($this->xpath->query('//p') as $p) { + foreach ($xpath->query('//p') as $p) { \assert($p instanceof \DOMElement); if ($p->childNodes->length === 1) { @@ -96,9 +92,9 @@ final class HtmlOutputNodeNormalizer } } - private function normalizeBr(): void + private function normalizeBr(\DOMXpath $xpath): void { - foreach ($this->xpath->query('//br') as $br) { + foreach ($xpath->query('//br') as $br) { \assert($br instanceof \DOMElement); $this->unwrapBr($br); diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php index bf2b41a81e..2a6a109505 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php @@ -97,7 +97,7 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor $this->invokeHtmlNode(new HtmlOutputUnfurlUrlNode()); } - (new HtmlOutputNodeNormalizer($this->getXPath()))->normalize(); + (new HtmlOutputNodeNormalizer())->normalize($this->getXPath()); // dynamic node handlers $this->invokeNodeHandlers('wcf\system\html\output\node\HtmlOutputNode', ['woltlab-metacode']); -- 2.20.1