Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import issue with Bard #65

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/Transformers/BardTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -54,6 +61,7 @@ public function transform(string $value): array
return $node;
})
->filter()
->values()
->all();
}

Expand Down
23 changes: 23 additions & 0 deletions tests/Transformers/BardTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
<h2>Blah blah</h2>
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()
{
Expand Down
Loading