Skip to content

Commit 160a2fa

Browse files
committed
Add support for the legacy quotes format
1 parent d0ef762 commit 160a2fa

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/WordPress/Gutenberg.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,28 @@ public static function toBard(array $config, Blueprint $blueprint, Field $field,
5252
}
5353

5454
if ($block['blockName'] === 'core/quote') {
55-
$innerHtmlWithoutBlockquote = (new Crawler($block['innerHTML']))->filter('blockquote')->html();
55+
// Quotes saved in the legacy format won't have any inner blocks, so we need to parse them manually.
56+
if (empty($block['innerBlocks'])) {
57+
$crawler = new Crawler($block['innerHTML']);
58+
59+
$block['innerBlocks'] = [
60+
[
61+
'blockName' => 'core/paragraph',
62+
'attrs' => [],
63+
'innerBlocks' => [],
64+
'innerHTML' => implode('', $crawler->filter('blockquote p')->each(fn (Crawler $p) => $p->outerHtml())),
65+
],
66+
];
67+
68+
// innerHTML should be the <blockquote> element, but without the nested <p> elements.
69+
$crawler
70+
->filter('p')
71+
->each(fn (Crawler $node) => $node->getNode(0)->parentNode->removeChild($node->getNode(0)));
72+
73+
$block['innerHTML'] = $crawler->html();
74+
}
75+
76+
$innerHtmlWithoutBlockquote = trim((new Crawler($block['innerHTML']))->filter('blockquote')->html());
5677

5778
return [
5879
'type' => 'blockquote',

0 commit comments

Comments
 (0)