public function filter()

in src/markdown-extensions/PrettyCodeBlocksFilter.php [26:59]


  public function filter(RenderContext $_, ASTNode $node): vec<ASTNode> {
    if (!$node is Blocks\CodeBlock) {
      return vec[$node];
    }
    if ($node is PrettyCodeBlock) {
      return vec[$node];
    }

    $info_string = $node->getInfoString();
    $classes = 'highlight fbgfm';
    $code = $node->getCode();
    if (
      $info_string !== null &&
      (
        Str\lowercase($info_string) === 'hack' ||
        Str\lowercase($info_string) === 'hacksignature'
      )
    ) {
      if (Str\lowercase($info_string) === 'hacksignature') {
        $code = Str\split($code, "\n") |> Vec\drop($$, 1) |> Str\join($$, "\n");
      }

      $classes .= ' source-language-'.$info_string;
      $info_string = 'PHP';
    } else {
      $classes .= ' output-block';
    }

    return vec[
      new Blocks\HTMLBlock('<div class="'.$classes.'">'),
      new PrettyCodeBlock($info_string, $code),
      new Blocks\HTMLBlock('</div>'),
    ];
  }