mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #17526 from CharlieEtienne/process-nodes-using
introduce processNodesUsing method
This commit is contained in:
@@ -83,6 +83,11 @@ class RichContentRenderer implements Htmlable
|
||||
*/
|
||||
protected array $cachedMergeTagValues = [];
|
||||
|
||||
/**
|
||||
* @var array<Closure>
|
||||
*/
|
||||
protected array $nodeProcessors = [];
|
||||
|
||||
/**
|
||||
* @param string | array<string, mixed> | null $content
|
||||
*/
|
||||
@@ -236,6 +241,20 @@ class RichContentRenderer implements Htmlable
|
||||
});
|
||||
}
|
||||
|
||||
public function processNodesUsing(Closure $callback): static
|
||||
{
|
||||
$this->nodeProcessors[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function processNodes(Editor $editor): void
|
||||
{
|
||||
foreach ($this->nodeProcessors as $processor) {
|
||||
$editor->descendants($processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<RichContentPlugin>
|
||||
*/
|
||||
@@ -341,6 +360,7 @@ class RichContentRenderer implements Htmlable
|
||||
$this->processCustomBlocks($editor);
|
||||
$this->processFileAttachments($editor);
|
||||
$this->processMergeTags($editor);
|
||||
$this->processNodes($editor);
|
||||
|
||||
return $editor->getHTML();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class ImageExtension extends BaseImage
|
||||
'parseHTML' => fn ($DOMNode) => $DOMNode->getAttribute('data-id') ?: null,
|
||||
'renderHTML' => fn ($attributes) => ['data-id' => $attributes->id ?? null],
|
||||
],
|
||||
'loading' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user