diff --git a/lib/runner.php b/lib/runner.php index 90b8f82..f1cdd18 100644 --- a/lib/runner.php +++ b/lib/runner.php @@ -146,15 +146,15 @@ function export_docblock( $element ) { } $output = array( - 'description' => preg_replace( '/[\n\r]+/', ' ', $docblock->getShortDescription() ), - 'long_description' => preg_replace( '/[\n\r]+/', ' ', $docblock->getLongDescription()->getFormattedContents() ), + 'description' => strip_newlines( $docblock->getShortDescription() ), + 'long_description' => strip_newlines( $docblock->getLongDescription()->getFormattedContents() ), 'tags' => array(), ); foreach ( $docblock->getTags() as $tag ) { $tag_data = array( 'name' => $tag->getName(), - 'content' => preg_replace( '/[\n\r]+/', ' ', format_description( $tag->getDescription() ) ), + 'content' => strip_newlines( format_description( $tag->getDescription() ) ), ); if ( method_exists( $tag, 'getTypes' ) ) { $tag_data['types'] = $tag->getTypes(); @@ -173,7 +173,7 @@ function export_docblock( $element ) { } // Description string. if ( method_exists( $tag, 'getDescription' ) ) { - $description = preg_replace( '/[\n\r]+/', ' ', format_description( $tag->getDescription() ) ); + $description = strip_newlines( format_description( $tag->getDescription() ) ); if ( ! empty( $description ) ) { $tag_data['description'] = $description; } @@ -354,3 +354,34 @@ function format_description( $description ) { } return $description; } + +/** + * Strips newline characters from descriptions, saving out pre-formatted blocks. + * + * @param string $description The descriptions to parse. + * @return string The string with newlines replaced by spaces, except in pre-formatted blocks. + */ +function strip_newlines( $description ) { + $pre_matcher = '/