Skip to content

Commit

Permalink
[TASK] Disable HTML formatting by default (MyIntervals#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
osbre authored and nlemoine committed Sep 19, 2023
1 parent e7f100b commit b2f6325
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/HtmlProcessor/AbstractHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ public function renderPreservesOuterHtmlProvidedToFromHtml(): void
self::assertEqualsHtml($formattedHtml, $html);
}

/**
* @test
*/
public function renderPreservesOriginalHtmlFormatting(): void
{
$rawHtml = '<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello world</title>
</head>
<body>
<li><em>Hello</em> world</li>
</body>
</html>';

$subject = TestingHtmlProcessor::fromHtml($rawHtml);
$renderedHtml = $subject->render();

self::assertEqualsHtml($rawHtml, $renderedHtml);
}

/**
* @test
*/
Expand Down

0 comments on commit b2f6325

Please sign in to comment.