diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eb18052..2f265d1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +## 8.0.0 + +### Changed +- Disable HTML formatting by default (#1214) + ## 7.0.0 ### Added diff --git a/README.md b/README.md index d0079d03..333b7b75 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,6 @@ The `HtmlNormalizer` class normalizes the given HTML in the following ways: - add a document type (HTML5) if missing - disentangle incorrectly nested tags - add HEAD and BODY elements (if they are missing) -- reformat the HTML The class can be used like this: diff --git a/src/HtmlProcessor/AbstractHtmlProcessor.php b/src/HtmlProcessor/AbstractHtmlProcessor.php index 2e203642..c63f7c5e 100644 --- a/src/HtmlProcessor/AbstractHtmlProcessor.php +++ b/src/HtmlProcessor/AbstractHtmlProcessor.php @@ -240,7 +240,7 @@ private function createRawDomDocument(string $html): void { $domDocument = new \DOMDocument(); $domDocument->strictErrorChecking = false; - $domDocument->formatOutput = true; + $domDocument->formatOutput = false; $libXmlState = \libxml_use_internal_errors(true); $domDocument->loadHTML($this->prepareHtmlForDomConversion($html)); \libxml_clear_errors(); diff --git a/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php b/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php index 758c9766..cffa3c2c 100644 --- a/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php +++ b/tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php @@ -108,6 +108,28 @@ public function renderPreservesOuterHtmlProvidedToFromHtml(): void self::assertEqualsHtml($formattedHtml, $html); } + /** + * @test + */ + public function renderPreservesOriginalHtmlFormatting(): void + { + $rawHtml = ' + + + + Hello world + + +
  • Hello world
  • + +'; + + $subject = TestingHtmlProcessor::fromHtml($rawHtml); + $renderedHtml = $subject->render(); + + self::assertEqualsHtml($rawHtml, $renderedHtml); + } + /** * @test */