diff --git a/bin/build-reference.php b/bin/build-reference.php index 2736ed26f..94ff21ebb 100755 --- a/bin/build-reference.php +++ b/bin/build-reference.php @@ -115,6 +115,12 @@ function render_nodes( array $nodes ): string { return rtrim( (string) $renderer->renderNodes( $nodes ) ); } +function node_children( Node $node ): array { + $children = $node->children(); + + return is_array( $children ) ? $children : iterator_to_array( $children ); +} + /** * Render the lede as inline HTML, without an outer `
`. If the lede * is a single Paragraph (the catalog convention), render its inline @@ -123,7 +129,7 @@ function render_nodes( array $nodes ): string { function render_lede( array $nodes ): string { $renderer = new HtmlRenderer( commonmark_env() ); if ( 1 === count( $nodes ) && $nodes[0] instanceof Paragraph ) { - $inline = iterator_to_array( $nodes[0]->children() ); + $inline = node_children( $nodes[0] ); return rtrim( (string) $renderer->renderNodes( $inline ) ); } return rtrim( (string) $renderer->renderNodes( $nodes ) ); @@ -148,7 +154,7 @@ function parse_body( string $md ): array { /** @var Document $doc */ $doc = $parser->parse( $md ); - $children = iterator_to_array( $doc->children() ); + $children = node_children( $doc ); // Find section boundaries (top-level H2 headings). $boundaries = array(); diff --git a/bin/run-snippets.php b/bin/run-snippets.php index 58df2d6cb..e59b94933 100755 --- a/bin/run-snippets.php +++ b/bin/run-snippets.php @@ -186,7 +186,7 @@ function write_expected_output( string $slug, string $filename, string $new_outp $parser = new \League\CommonMark\Parser\MarkdownParser( commonmark_env() ); $tree = $parser->parse( $body ); - $kids = iterator_to_array( $tree->children() ); + $kids = node_children( $tree ); // Find the snippet metadata HtmlBlock whose meta names this filename. $snippet_idx = null;