Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/build-reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<p>`. If the lede
* is a single Paragraph (the catalog convention), render its inline
Expand All @@ -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 ) );
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion bin/run-snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading