Skip to content

Commit

Permalink
Fix doc generation for when '%' exist in the docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Jun 1, 2023
1 parent d0e28b5 commit 033defc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 12 additions & 2 deletions docgen/FunctionDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,19 @@ public function asMethodTag(): Method
$description .= '<h2>Returns</h2>';
$description .= Parsers::$markdown->text($this->returnDescription);
}

//
// Perform some cleanup on the description we just built
//

// Replace newlines with `<br>` tags since IDEs parse docblocks as HTML
$descriptionBody = trim(preg_replace('/\n/', ' ', $this->summary . '<br>' . $description));

// Don't allow trailing `<br>` tags
$descriptionBody = preg_replace('/<br>$/', '', $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,
Expand All @@ -94,7 +104,7 @@ public function asMethodTag(): Method
}),
$this->returnType,
true,
$description
new Description($descriptionBody)
);
}

Expand Down
4 changes: 1 addition & 3 deletions tools/phpDocGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 033defc

Please sign in to comment.