From 5a36502160c3c6fe115a1f2fa50cce7347cc6a96 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 3 Nov 2024 20:26:51 +0100 Subject: [PATCH] Generators/Text: trim code titles As things were, whitespace at the start/end of a title could cause unnecessary line wrapping of the title. Fixed now. Includes updated test expectations. --- src/Generators/Text.php | 4 ++-- .../Expectations/ExpectedOutputCodeTitleWhitespace.txt | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Generators/Text.php b/src/Generators/Text.php index 419bcc3d56..e57556d08f 100644 --- a/src/Generators/Text.php +++ b/src/Generators/Text.php @@ -133,7 +133,7 @@ protected function printCodeComparisonBlock(DOMNode $node) { $codeBlocks = $node->getElementsByTagName('code'); $first = trim($codeBlocks->item(0)->nodeValue); - $firstTitle = $codeBlocks->item(0)->getAttribute('title'); + $firstTitle = trim($codeBlocks->item(0)->getAttribute('title')); $firstTitleLines = []; $tempTitle = ''; @@ -168,7 +168,7 @@ protected function printCodeComparisonBlock(DOMNode $node) $firstLines = explode("\n", $first); $second = trim($codeBlocks->item(1)->nodeValue); - $secondTitle = $codeBlocks->item(1)->getAttribute('title'); + $secondTitle = trim($codeBlocks->item(1)->getAttribute('title')); $secondTitleLines = []; $tempTitle = ''; diff --git a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.txt b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.txt index 80a6cc690b..0db5a7dfae 100644 --- a/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.txt +++ b/tests/Core/Generators/Expectations/ExpectedOutputCodeTitleWhitespace.txt @@ -6,15 +6,13 @@ This is a standard block. ----------------------------------------- CODE COMPARISON ------------------------------------------ -| Valid: spaces at start of description. | Invalid: spaces at end making line > 46 chars. | -| | | +| Valid: spaces at start of description. | Invalid: spaces at end making line > 46 chars. | ---------------------------------------------------------------------------------------------------- | // Dummy. | // Dummy. | ---------------------------------------------------------------------------------------------------- ----------------------------------------- CODE COMPARISON ------------------------------------------ -| Valid: spaces at start + end of description. | Invalid: spaces ' ' in description. | -| | | +| Valid: spaces at start + end of description. | Invalid: spaces ' ' in description. | ---------------------------------------------------------------------------------------------------- | // Note: description above without the | // Dummy. | | // trailing whitespace fits in 46 chars. | |