From 1031c0ffb0cec6165acc8ca15b9708d51fb23af6 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 19 Dec 2024 16:15:06 +0000 Subject: [PATCH 1/3] Remove all indexes. --- src/Transformers/BardTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Transformers/BardTransformer.php b/src/Transformers/BardTransformer.php index ac5dca0..a57e002 100644 --- a/src/Transformers/BardTransformer.php +++ b/src/Transformers/BardTransformer.php @@ -54,6 +54,7 @@ public function transform(string $value): array return $node; }) ->filter() + ->values() ->all(); } From d664bf9daf3b6b331fa8e53e652433b480fc89d9 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 19 Dec 2024 16:15:37 +0000 Subject: [PATCH 2/3] Ensure `text` nodes are wrapped in `paragraph` nodes --- src/Transformers/BardTransformer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Transformers/BardTransformer.php b/src/Transformers/BardTransformer.php index a57e002..bb11e2a 100644 --- a/src/Transformers/BardTransformer.php +++ b/src/Transformers/BardTransformer.php @@ -28,6 +28,13 @@ public function transform(string $value): array return collect($value) ->map(function (array $node): ?array { + if ($node['type'] === 'text') { + return [ + 'type' => 'paragraph', + 'content' => [$node], + ]; + } + if ($node['type'] === 'image' && $this->field->get('container') && isset($this->config['assets_base_url'])) { $assetContainer = AssetContainer::find($this->field->get('container')); From fd57e0f6eed1e37ac278407ef9a59b87e772f152 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 19 Dec 2024 16:37:40 +0000 Subject: [PATCH 3/3] Add test. --- tests/Transformers/BardTransformerTest.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Transformers/BardTransformerTest.php b/tests/Transformers/BardTransformerTest.php index 985ea1c..59605c9 100644 --- a/tests/Transformers/BardTransformerTest.php +++ b/tests/Transformers/BardTransformerTest.php @@ -83,6 +83,29 @@ public function it_converts_html_to_prosemirror() ]], $output); } + #[Test] + public function it_handles_text_without_paragraph_tags() + { + $transformer = new BardTransformer( + import: $this->import, + blueprint: $this->blueprint, + field: $this->field, + config: [] + ); + + $output = $transformer->transform(<<<'HTML' +

Blah blah

+Nam voluptatem rem molestiae cumque doloremque. Saepe animi deserunt Maxime iam et inventore. ipsam in dignissimos qui occaecati. +HTML); + + $this->assertEquals([ + ['type' => 'heading', 'attrs' => ['level' => 2, 'textAlign' => 'left'], 'content' => [['type' => 'text', 'text' => 'Blah blah']]], + ['type' => 'paragraph', 'content' => [ + ['type' => 'text', 'text' => 'Nam voluptatem rem molestiae cumque doloremque. Saepe animi deserunt Maxime iam et inventore. ipsam in dignissimos qui occaecati.'], + ]], + ], $output); + } + #[Test] public function it_handles_images() {