From 033defc170137e3ec7b930478091afcadb173c42 Mon Sep 17 00:00:00 2001 From: Vladimir Jimenez Date: Wed, 31 May 2023 17:59:25 -0700 Subject: [PATCH] Fix doc generation for when '%' exist in the docblocks --- docgen/FunctionDocumentation.php | 14 ++++++++++++-- tools/phpDocGen.php | 4 +--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docgen/FunctionDocumentation.php b/docgen/FunctionDocumentation.php index fdfaa9a..3fbeffd 100644 --- a/docgen/FunctionDocumentation.php +++ b/docgen/FunctionDocumentation.php @@ -83,9 +83,19 @@ public function asMethodTag(): Method $description .= '

Returns

'; $description .= Parsers::$markdown->text($this->returnDescription); } + + // + // Perform some cleanup on the description we just built + // + + // Replace newlines with `
` tags since IDEs parse docblocks as HTML $descriptionBody = trim(preg_replace('/\n/', ' ', $this->summary . '
' . $description)); + + // Don't allow trailing `
` tags $descriptionBody = preg_replace('/
$/', '', $descriptionBody); - $description = new Description($descriptionBody); + + // Escape percent signs because this string will go through a `sprintf()` call so having a single `%` will cause an error + $descriptionBody = preg_replace('/([^%])%([^%])/m', '\1%%\2', $descriptionBody); return new Method( $this->name, @@ -94,7 +104,7 @@ public function asMethodTag(): Method }), $this->returnType, true, - $description + new Description($descriptionBody) ); } diff --git a/tools/phpDocGen.php b/tools/phpDocGen.php index 09d144b..70e71cb 100755 --- a/tools/phpDocGen.php +++ b/tools/phpDocGen.php @@ -114,9 +114,7 @@ function buildCoreFunctionLoader() $docBlockLiteral = writeDocBlock(new DocBlock( '', null, - __::map($registry->methods, function (FunctionDocumentation $fxnDoc) { - return $fxnDoc->asMethodTag(); - }) + __::map($registry->methods, static fn (FunctionDocumentation $fxnDoc) => $fxnDoc->asMethodTag()) )); /** @var Stmt $astNode */