Skip to content

Commit

Permalink
[BUGFIX] Remove whitespace and duplicate empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed Sep 6, 2024
1 parent ef72f97 commit 6a8afce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Classes/Util/CodeSnippetCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,25 @@ public static function writeSimpleFile($content, $path): void
public static function writeFile(array $entry, String $content, String $rstContent = '', $overwriteRst = false, String $indexContent = '', $overwriteIndex = false): void
{
$content = '.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets' . LF . $content;

if (!$entry['targetFileName']) {
throw new InvalidConfigurationException('targetFileName not set for action ' . $entry['action']);
}
if (!$content) {
throw new InvalidConfigurationException('No content found for file ' . $entry['targetFileName']);
}

// Ensure no trailing whitespaces on empty lines
$content = preg_replace("/\n\s*\n/", "\n\n", $content);

// Ensure content ends with exactly one empty line
$content = trim($content) . "\n";

$filename = self::$configPath . '/' . $entry['targetFileName'];
if (!file_exists(dirname($filename))) {
mkdir(dirname($filename), 0755, true);
}
$content = preg_replace("/\n\s+\n/", "\n\n", $content);

GeneralUtility::writeFile(
$filename,
$content,
Expand Down

0 comments on commit 6a8afce

Please sign in to comment.