Skip to content

Make Image as block level node? #941

Answered by colinodell
chaot1xMD asked this question in Q&A
Discussion options

You must be logged in to vote

I would like images to be rendered outside of p tags, but I'm not sure how to do it if it's possible

You don't need to change the image node from an inline to a block, you just need to move it outside of its parent Paragraph block and into the root Document block. Something like this should work (untested):

class RemoveImagesFromParagraphsListener
{
    public function onDocumentParsed(DocumentParsedEvent $event): void
    {
        $document = $event->getDocument();
        
        $images = (new Query())->where(Query::type(Image::class))->findAll();

        foreach ($images as $image) {
            if ($image->parent() instanceof Paragraph::class && $image->previous() === null && $i…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@chaot1xMD
Comment options

Answer selected by chaot1xMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants