diff --git a/src/Generators/Markdown.php b/src/Generators/Markdown.php index 76dbb0605f..eb51b60c77 100644 --- a/src/Generators/Markdown.php +++ b/src/Generators/Markdown.php @@ -117,14 +117,34 @@ 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); - $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 ($currentLine === '') { + // The text contained a blank line. Respect this. + $lines[] = ''; + continue; + } + + // Check if the _next_ line is blank. + if (isset($nodeLines[($i + 1)]) === false + || trim($nodeLines[($i + 1)]) === '' + ) { + // Next line is blank, just add the line. + $lines[] = $currentLine; + } else { + // Ensure that line breaks are respected in markdown. + $lines[] = $currentLine.' '; + } + } + + echo implode(PHP_EOL, $lines).PHP_EOL; }//end printTextBlock() diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.md b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.md index 89ae055bfb..8dbf564261 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.md +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeComparisonLineLength.md @@ -2,8 +2,8 @@ ## Code Comparison, line length -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 diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md index 6b3d6ed107..f8663f14f3 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardBlankLines.md @@ -4,8 +4,8 @@ There is a blank line at the start of this standard. - And the above blank line is also deliberate to test part of the logic. +And the above blank line is also deliberate to test part of the logic. - Let's also end on a blank line to test that too. +Let's also end on a blank line to test that too. Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md index f682daf611..6183dc0037 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardEncoding.md @@ -2,7 +2,7 @@ ## Standard Element, handling of HTML tags -The use of *tags* in standard descriptions is allowed and their handling should be *safeguarded*. - Other tags, like <a href="example.com">link</a>, <b>bold</bold>, <script></script> are not allowed and will be encoded for display when the HTML or Markdown report is used. +The use of *tags* in standard descriptions is allowed and their handling should be *safeguarded*. +Other tags, like <a href="example.com">link</a>, <b>bold</bold>, <script></script> are not allowed and will be encoded for display when the HTML or Markdown report is used. Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md index 1f3916153e..46bea4c349 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardIndent.md @@ -2,9 +2,9 @@ ## Standard Element, indentation should be ignored -This line has no indentation. - This line has 4 spaces indentation. - This line has 8 spaces indentation. - This line has 4 spaces indentation. +This line has no indentation. +This line has 4 spaces indentation. +This line has 8 spaces indentation. +This line has 4 spaces indentation. Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md index 1a2cd9f19c..c94bed46b5 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md +++ b/tests/Core/Generators/Expectations/ExpectedOutputStandardLineWrapping.md @@ -2,8 +2,8 @@ ## Standard Element, line wrapping handling -This line has to be exactly 99 chars to test part of the logic.------------------------------------ - And this line has to be exactly 100 chars.---------------------------------------------------------- - And here we have a line which should start wrapping as it is longer than 100 chars. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pellentesque iaculis enim quis hendrerit. Morbi ultrices in odio pharetra commodo. +This line has to be exactly 99 chars to test part of the logic.------------------------------------ +And this line has to be exactly 100 chars.---------------------------------------------------------- +And here we have a line which should start wrapping as it is longer than 100 chars. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pellentesque iaculis enim quis hendrerit. Morbi ultrices in odio pharetra commodo. Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer)
Valid: contains line which is too long.