paquettg / php-html-parser

An HTML DOM parser. It allows you to manipulate HTML. Find tags on an HTML page with selectors just like jQuery.
MIT License
2.37k stars 462 forks source link

how do I get output with linebreaks? #279

Open skinofthesoul opened 3 years ago

skinofthesoul commented 3 years ago

I'm not sure whether I'm simply not doing this right – hopefully there is an easy fix :-)

I'm using PHPHtmlParser to grab all the images on a page and add a sizes attribute to them. All of this works fantastically, so thank you for that! However, if the page contains inline javascript, that doesn't work anymore afterwards, and it seems to be because all the line breaks are removed. My loading code looks like this:

$dom = new Dom;
$dom->loadStr($this->grav->output, (new Options())->setCleanupInput(false));

And after I've made all the changes and I dump the $dom object, I get the following output: phphtmlparser

The only HTML I can find is under content, and it has linebreaks. Perfect. However, I can't seem to get it as output? Both $dom->outerHtml and $dom->innerHtml give me the HTML without linebreaks…

What can I do?