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

Text doc generator does not allow for multi-line rule explanations #2541

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 25 additions & 17 deletions src/Generators/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,42 @@ protected function printTextBlock(\DOMNode $node)
$text = str_replace('<em>', '*', $text);
$text = str_replace('</em>', '*', $text);

$lines = [];
$tempLine = '';
$words = explode(' ', $text);
$nodeLines = explode("\n", $text);
$lines = [];

foreach ($nodeLines as $currentLine) {
$currentLine = trim($currentLine);
if ($currentLine === '') {
// The text contained a blank line. Respect this.
$lines[] = '';
continue;
}

foreach ($words as $word) {
if (strlen($tempLine.$word) >= 99) {
if (strlen($tempLine.$word) === 99) {
// Adding the extra space will push us to the edge
// so we are done.
$lines[] = $tempLine.$word;
$tempLine = '';
} else if (strlen($tempLine.$word) === 100) {
$tempLine = '';
$words = explode(' ', $currentLine);

foreach ($words as $word) {
$currentLength = strlen($tempLine.$word);
if ($currentLength < 99) {
$tempLine .= $word.' ';
continue;
}

if ($currentLength === 99 || $currentLength === 100) {
// We are already at the edge, so we are done.
$lines[] = $tempLine.$word;
$tempLine = '';
} else {
$lines[] = rtrim($tempLine);
$tempLine = $word.' ';
}
} else {
$tempLine .= $word.' ';
}//end foreach

if ($tempLine !== '') {
$lines[] = rtrim($tempLine);
}
}//end foreach

if ($tempLine !== '') {
$lines[] = rtrim($tempLine);
}

echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;

}//end printTextBlock()
Expand Down