Merge pull request #17526 from CharlieEtienne/process-nodes-using

introduce processNodesUsing method
This commit is contained in:
Dan Harrin
2025-09-10 10:28:39 +01:00
committed by GitHub
2 changed files with 21 additions and 0 deletions
@@ -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' => [],
];
}
}