html-minifier
html-minifier copied to clipboard
Advanced optimisation does not respect required inline white spaces
Hi,
Your minifier is one of the most awesome I could find ! Thanks a lot for this job ! However, I had a little trouble using advanced optimisation option.
For that kind of html :
<p>Here is some <strong>bold</strong> text</p>
It will output :
<p>Here is some<strong>bold</strong>text</p>
I also made a test with more inline tags
<p>
And here is some <strong>bold</strong> with <b>b</b> tag.
Hey, what about <em>emphasis</em> and <i>italic</i> ?
And also <u>underline</u> string ?!
</p>
Which gave me this :
<p>And here is some<strong>bold</strong> with <b>b</b> tag.
Hey, what about <em>emphasis</em> and <i>italic</i> ?
And also <u>underline</u>string ?!</p>
Considering that the standard optimisation level works fine, I fixed it using this code I'm not really proud of :
$minifier = new \zz\Html\HTMLMinify($html, array(
'doctype' => \zz\Html\HTMLMinify::DOCTYPE_HTML5,
'optimizationLevel' => \zz\Html\HTMLMinify::OPTIMIZATION_ADVANCED,
));
$minified = $minifier->process();
$lines = preg_split('/(\r\n|\n)/', $minified);
$minified = '';
$forceNewLine = false;
foreach($lines as $line) {
// For now an then add new line characters after this one
if(mb_strpos($line, '<pre>') !== false)
$forceNewLine = true;
// Since here, stop adding new line characters
if(mb_strpos($line, '</pre>') !== false)
$forceNewLine = false;
$minified .= $line;
if($forceNewLine)
$minified .= "\r\n";
}
$html = $minified;
I would prefer using the package dedicated option, is there a way to fix it in your code ?
This issue also impact for me.
Same here. Any fixes available? Otherwise it's useless...
I have forked the project and fixed main issues at https://github.com/raivisdejus/html-minifier If you see any new issues, please let me know