zaininnari / html-minifier Goto Github PK
View Code? Open in Web Editor NEWhtml-minifier by Blink HTMLTokenizer. HTML Parser and HTML Minify by PHP.
License: Other
html-minifier by Blink HTMLTokenizer. HTML Parser and HTML Minify by PHP.
License: Other
I get this warning multiple times when using html-minifier after upgrading to PHP 7.3.
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ...
[....]/vendor/zaininnari/html-minifier/src/zz/Html/HTMLTokenizer.php on line xyz
kirby-deprecated-plugins/kirby-html-minifier#5
I use this for a plugin in Kirby CMS. Inline svg seems to fail.
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 ?
Please add .gitattributes file for installing this library via composer with --prefer-dist
option. Folder "tests" should be with export-ignore
.
Unfortunately, it seems that whitespaces around tags within text contents are removed.
<p>
<strong>Keywords</strong> are really important!
</p>
<p><strong>Keywords</strong>are really important!</p>
Keywordsare really important!
$minimized = HTMLMinify::minify($html, [
'doctype' => HTMLMinify::DOCTYPE_HTML5,
'optimizationLevel' => HTMLMinify::OPTIMIZATION_ADVANCED
]);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.