Skip to content

Generators: don't print standard when it's empty #819

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

Merged
merged 1 commit into from
Feb 15, 2025
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
7 changes: 6 additions & 1 deletion src/Generators/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ protected function printTextBlock(DOMNode $node)
*/
protected function getFormattedTextBlock(DOMNode $node)
{
$content = trim($node->nodeValue);
$content = $node->nodeValue;
if (empty($content) === true) {
return '';
}

$content = trim($content);
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));

// Allow only em tags.
Expand Down
7 changes: 6 additions & 1 deletion src/Generators/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ protected function printTextBlock(DOMNode $node)
*/
protected function getFormattedTextBlock(DOMNode $node)
{
$content = trim($node->nodeValue);
$content = $node->nodeValue;
if (empty($content) === true) {
return '';
}

$content = trim($content);
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
$content = str_replace('<em>', '*', $content);
$content = str_replace('</em>', '*', $content);
Expand Down
7 changes: 6 additions & 1 deletion src/Generators/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ protected function printTextBlock(DOMNode $node)
*/
protected function getFormattedTextBlock(DOMNode $node)
{
$text = trim($node->nodeValue);
$text = $node->nodeValue;
if (empty($text) === true) {
return '';
}

$text = trim($text);
$text = str_replace('<em>', '*', $text);
$text = str_replace('</em>', '*', $text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<h1>GeneratorTest Coding Standards</h1>
<a name="Standard-Element,-no-content" />
<h2>Standard Element, no content</h2>
<p class="text"></p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Lorem ipsum dolor sit amet.</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

## Standard Element, no content


<table>
<tr>
<th>Valid: Lorem ipsum dolor sit amet.</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
| GENERATORTEST CODING STANDARD: STANDARD ELEMENT, NO CONTENT |
---------------------------------------------------------------



----------------------------------------- CODE COMPARISON ------------------------------------------
| Valid: Lorem ipsum dolor sit amet. | Invalid: Maecenas non rutrum dolor. |
----------------------------------------------------------------------------------------------------
Expand Down
Loading