diff --git a/features/scaffold-package-readme.feature b/features/scaffold-package-readme.feature index 513f28f..e2c9f44 100644 --- a/features/scaffold-package-readme.feature +++ b/features/scaffold-package-readme.feature @@ -386,3 +386,46 @@ Feature: Scaffold a README.md file for an existing package """ **Alias:** `cpt` """ + + Scenario: README correctly indents multi-paragraph parameter descriptions + Given an empty directory + And a foo/command.php file: + """ + ] + * : Read content from . If this value is present, the + * `--content` argument will be ignored. + * + * Passing `-` will cause content to + * be read from STDIN. + * + * @when before_wp_load + */ + public function __invoke( $args, $assoc_args ) {} + } + WP_CLI::add_command( 'multi-para-test', 'Multi_Para_Test_Command' ); + """ + And a foo/composer.json file: + """ + { + "name": "wp-cli/multi-para-test", + "description": "Test", + "extra": { + "commands": ["multi-para-test"] + } + } + """ + + When I run `wp --require=foo/command.php scaffold package-readme foo` + Then the foo/README.md file should exist + And the contents of the foo/README.md file should match /\t\t.*Read content from/ + And the contents of the foo/README.md file should match /\t\t.*Passing/ diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 5e18743..cedfee4 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -365,7 +365,7 @@ public function package_readme( $args, $assoc_args ) { $longdesc = (string) preg_replace( '/##\s(.+)/', '**$1**', $longdesc ); // definition lists - $longdesc = preg_replace_callback( '/([^\n]+)\n: (.+?)(\n\n|$)/s', [ __CLASS__, 'rewrap_param_desc' ], $longdesc ); + $longdesc = preg_replace_callback( '/([^\n]+)\n: (.+?)(\n\n(?=\S)|\n*$)/s', [ __CLASS__, 'rewrap_param_desc' ], $longdesc ); $command_data = [ 'name' => "wp {$command}", @@ -777,14 +777,16 @@ public function package_tests( $args, $assoc_args ) { private static function rewrap_param_desc( $matches ) { $param = $matches[1]; - $desc = self::indent( "\t\t", $matches[2] ); + $desc = self::indent( "\t\t", rtrim( $matches[2] ) ); return "\t$param\n$desc\n\n"; } private static function indent( $whitespace, $text ) { $lines = explode( "\n", $text ); foreach ( $lines as &$line ) { - $line = $whitespace . $line; + if ( '' !== $line ) { + $line = $whitespace . $line; + } } return implode( "\n", $lines ); }