update src attribute using event #647
-
Using the commonmark package the first time this excessive. I've used the code to add a class to an image to make images hidden, since we are facing much abuses when users are allowed to inlclude images by markdown. The idea was:
ImageManipulatorProcessor
Is it not possible to change already set attributes after they are rendered? How to update the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The public function __invoke(DocumentParsedEvent $e)
{
$walker = $e->getDocument()->walker();
while ($event = $walker->next()) {
$node = $event->getNode();
if (!($node instanceof Image) || !$event->isEntering()) {
continue;
}
if ($node instanceof Image) {
- $node->data['attributes']['src'] = '';
+ $node->setUrl('');
}
}
} Alternatively, if your goal is to completely remove the image, you could try removing the whole image element from the AST here (though that might be complex to implement since I don't think Another option would be replacing the image renderer with something that always returns an empty string. Or you could disable/remove the I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
@colinodell Thanks, working fine, I'll stay with the replacing function of the |
Beta Was this translation helpful? Give feedback.
The
src
is not stored in theattributes
array -Image
extends from AbstractWebResource which stores the URL in its own field. Your code should work with a simple change:Alternatively, if your goal is to completely remove the image, you c…