injectMacros method

String injectMacros(
  1. String rawDocs
)

Replace {@macro ...} in API comments with the contents of the macro

Syntax:

{@macro NAME}

Example:

You define the template in any comment for a documentable entity like:

{@template foo}
Foo contents!
{@endtemplate}

and them somewhere use it like this:

Some comments
{@macro foo}
More comments

Which will render

Some comments
Foo contents!
More comments

Implementation

String injectMacros(String rawDocs) {
  return rawDocs.replaceAllMapped(_macroRegExp, (match) {
    var macro = packageGraph.getMacro(match[1]);
    if (macro == null) {
      warn(PackageWarning.unknownMacro, message: match[1]);
    }
    macro = processCommentDirectives(macro ?? '');
    return macro;
  });
}