-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I found an issue with the source_block_raw method in /src/parser/content-parser.php.
Current Behavior:
In the current implementation, the function only returns the first matched DOMElement when there are multiple elements within the core/html block. Specifically, it uses:
$attribute_value = trim( $crawler->outerHtml() );
This causes a problem when the core/html block contains multiple DOMElement objects. For example, consider the following HTML content:
<h2>My HTML heading</h2><p>My HTML paragraph</p>
Currently, only the first element (<h2>My HTML heading</h2>) is returned, while the rest of the elements are ignored.
Proposed Solution:
To address this, I propose modifying the function to iterate over all matched elements, collect their outer HTML, and then concatenate them together. This can be accomplished with the following change:
$attribute_values = $crawler->each(function ($node) {
return trim( $node->outerHtml() );
});
$attribute_value = trim( implode( '', $attribute_values ) );
This approach ensures that all DOMElement objects within the core/html block are captured and returned correctly.
Example Output:
With this change, the example input:
<h2>My HTML heading</h2><p>My HTML paragraph</p>
Will be correctly handled, returning both elements as expected, instead of only the first.
Please let me know if this proposed fix is suitable or if further adjustments are needed.