Skip to content

Commit f4a054d

Browse files
committed
Merge branch '1.x'
2 parents 4e07f17 + e6ef57e commit f4a054d

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.9.0 (2025-10-31)
4+
5+
* Improve support for Gutenberg quotes #115 by @duncanmcclean
6+
7+
8+
39
## 1.8.5 (2025-10-02)
410

511
### What's fixed

src/WordPress/Gutenberg.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,54 @@ public static function toBard(array $config, Blueprint $blueprint, Field $field,
5252
}
5353

5454
if ($block['blockName'] === 'core/quote') {
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+
$crawler
60+
->filter('blockquote p')
61+
->each(function (Crawler $nodeCrawler) use (&$block) {
62+
$block['innerBlocks'][] = [
63+
'blockName' => 'core/paragraph',
64+
'attrs' => [],
65+
'innerBlocks' => [],
66+
'innerHTML' => $nodeCrawler->outerHtml(),
67+
];
68+
});
69+
70+
// innerHTML should be the <blockquote> element, but without the nested <p> elements.
71+
$crawler
72+
->filter('p')
73+
->each(fn (Crawler $node) => $node->getNode(0)->parentNode->removeChild($node->getNode(0)));
74+
75+
$block['innerHTML'] = $crawler->html();
76+
}
77+
78+
$innerHtmlWithoutBlockquote = trim((new Crawler($block['innerHTML']))->filter('blockquote')->html());
79+
5580
return [
5681
'type' => 'blockquote',
5782
'content' => collect($block['innerBlocks'])
5883
->filter(fn ($block) => $block['blockName'] === 'core/paragraph')
5984
->map(fn (array $block) => static::renderHtmlToProsemirror($field, $block['innerHTML']))
85+
->when(! empty($innerHtmlWithoutBlockquote), function ($collection) use ($innerHtmlWithoutBlockquote) {
86+
// When the blockquote contains a <cite>, we need to append it to the blockquote.
87+
if (Str::startsWith($innerHtmlWithoutBlockquote, '<cite>')) {
88+
return $collection->push([
89+
'type' => 'paragraph',
90+
'attrs' => ['textAlign' => 'left'],
91+
'content' => [
92+
[
93+
'type' => 'hardBreak',
94+
],
95+
[
96+
'type' => 'text',
97+
'text' => strip_tags($innerHtmlWithoutBlockquote),
98+
],
99+
],
100+
]);
101+
}
102+
})
60103
->values()
61104
->all(),
62105
];

tests/WordPress/GutenbergTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ public function it_transforms_quotes_blocks()
163163
<p>Great achievements are born from collaboration; together, we can turn the impossible into the possible.</p>
164164
<!-- /wp:paragraph --></blockquote>
165165
<!-- /wp:quote -->
166+
167+
<!-- wp:quote -->
168+
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
169+
<p>Exercitation nostrud minim proident minim minim aliqua tempor incididunt laboris in. Id non reprehenderit sint excepteur cillum.</p>
170+
<!-- /wp:paragraph --><cite>John Doe</cite></blockquote>
171+
<!-- /wp:quote -->
172+
173+
<!-- wp:quote {"align":"left"} -->
174+
<blockquote class="wp-block-quote has-text-align-left">
175+
<p>“Ea eiusmod ad non magna et tempor non qui magna. Id labore veniam Lorem do elit do veniam magna et aliquip voluptate consectetur nulla aliquip.”</p>
176+
<p>“Minim nisi adipisicing velit. In in magna veniam minim reprehenderit esse ut ut ea nisi sint irure nostrud. Ad dolor eiusmod culpa.”</p>
177+
<cite>John Doe</cite>
178+
</blockquote>
179+
<!-- /wp:quote -->
166180
HTML
167181
);
168182

@@ -182,6 +196,72 @@ public function it_transforms_quotes_blocks()
182196
],
183197
],
184198
],
199+
[
200+
'type' => 'blockquote',
201+
'content' => [
202+
[
203+
'type' => 'paragraph',
204+
'attrs' => ['textAlign' => 'left'],
205+
'content' => [
206+
[
207+
'type' => 'text',
208+
'text' => 'Exercitation nostrud minim proident minim minim aliqua tempor incididunt laboris in. Id non reprehenderit sint excepteur cillum.',
209+
],
210+
],
211+
],
212+
[
213+
'type' => 'paragraph',
214+
'attrs' => ['textAlign' => 'left'],
215+
'content' => [
216+
[
217+
'type' => 'hardBreak',
218+
],
219+
[
220+
'type' => 'text',
221+
'text' => 'John Doe',
222+
],
223+
],
224+
],
225+
],
226+
],
227+
[
228+
'type' => 'blockquote',
229+
'content' => [
230+
[
231+
'type' => 'paragraph',
232+
'attrs' => ['textAlign' => 'left'],
233+
'content' => [
234+
[
235+
'type' => 'text',
236+
'text' => '“Ea eiusmod ad non magna et tempor non qui magna. Id labore veniam Lorem do elit do veniam magna et aliquip voluptate consectetur nulla aliquip.”',
237+
],
238+
],
239+
],
240+
[
241+
'type' => 'paragraph',
242+
'attrs' => ['textAlign' => 'left'],
243+
'content' => [
244+
[
245+
'type' => 'text',
246+
'text' => '“Minim nisi adipisicing velit. In in magna veniam minim reprehenderit esse ut ut ea nisi sint irure nostrud. Ad dolor eiusmod culpa.”',
247+
],
248+
],
249+
],
250+
[
251+
'type' => 'paragraph',
252+
'attrs' => ['textAlign' => 'left'],
253+
'content' => [
254+
[
255+
'type' => 'hardBreak',
256+
],
257+
[
258+
'type' => 'text',
259+
'text' => 'John Doe',
260+
],
261+
],
262+
],
263+
],
264+
],
185265
], $output);
186266
}
187267

0 commit comments

Comments
 (0)