Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable HTML formatting by default #1214

Merged
merged 7 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed

## 8.0.0

### Changed
- Disable HTML formatting by default (#1214)

osbre marked this conversation as resolved.
Show resolved Hide resolved
## 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>';
osbre marked this conversation as resolved.
Show resolved Hide resolved
osbre marked this conversation as resolved.
Show resolved Hide resolved

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

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

/**
* @test
*/
Expand Down