diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 0ca4496963..8e2001e2e5 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -237,14 +237,35 @@ protected function printTextBlock(DOMNode $node) $content = trim($node->nodeValue); $content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401)); - // Use the correct line endings based on the OS. - $content = str_replace("\n", PHP_EOL, $content); - - // Allow em tags only. + // Allow only em tags. $content = str_replace('<em>', '', $content); $content = str_replace('</em>', '', $content); - echo "
$content
".PHP_EOL; + $nodeLines = explode("\n", $content); + $lineCount = count($nodeLines); + $lines = []; + + for ($i = 0; $i < $lineCount; $i++) { + $currentLine = trim($nodeLines[$i]); + + if (isset($nodeLines[($i + 1)]) === false) { + // We're at the end of the text, just add the line. + $lines[] = $currentLine; + } else { + $nextLine = trim($nodeLines[($i + 1)]); + if ($nextLine === '') { + // Next line is a blank line, end the paragraph and start a new one. + // Also skip over the blank line. + $lines[] = $currentLine.''.PHP_EOL.'';
+ ++$i;
+ } else {
+ // Next line is not blank, so just add a line break.
+ $lines[] = $currentLine.'
'.PHP_EOL;
+ }
+ }
+ }
+
+ echo '
'.implode('', $lines).'
'.PHP_EOL; }//end printTextBlock() diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html index 2f7abc69a4..b876e6b1e9 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.html @@ -72,8 +72,8 @@Ensure there is no PHP "Warning: str_repeat(): Second argument has to be greater than or equal to 0". - Ref: squizlabs/PHP_CodeSniffer#2522
+Ensure there is no PHP "Warning: str_repeat(): Second argument has to be greater than or equal to 0".
+Ref: squizlabs/PHP_CodeSniffer#2522
Valid: contains line which is too long. | diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html index 5c6539d0ca..4c45757b57 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.html @@ -72,11 +72,9 @@