searchturbine / phpwee-php-minifier

Open-source (BSD) PHP inline minifier functions for HTML, XHTML, HTML5, CSS 1-3 and Javascript. http://searchturbine.com/php/phpwee
Other
79 stars 46 forks source link

How to ignore copyrights in HTML from compressing? #1

Open julkue opened 9 years ago

julkue commented 9 years ago

Hello,

my copyrights look like

<!--
 /**
  * Some copyright
  *
  */
-->

How can I ignore those from compressing HTML?

ztkemsley commented 9 years ago

The short answer is putting [] square brackets inside the comment will keep it included - and its whitespace intact.

<!--[
 /**
  * Some copyright
  *
  */
]-->

The alternative - we can edit HTMLmin.php to keep the comment:

Line 50:

    foreach ($xpath->query('//comment()') as $comment) {
                $val= $comment->nodeValue;
                if( strpos($val,'[')!==0 &&  strpos(strtolower($val),'copyright')!==0 ){
                    $comment->parentNode->removeChild($comment);
                }
            }
julkue commented 9 years ago

Thanks for the hint. But isn't it possible to pass a individual structure for copyrights as a parameter?

ztkemsley commented 9 years ago

Its a good idea. I can add that feature no problem.

For now you could just so a str_replace

 str_replace("</body>",$mynotice.”</body>”,$html)

On Mar 31, 2015, at 11:35 PM, Julian notifications@github.com wrote:

Thanks for the hint. But isn't it possible to pass a individual structure for copyrights as a parameter?

Am 31. Mär. 2015 17:45, um 17:45, ztkemsley notifications@github.com schrieb:

The short answer is putting [] square brackets firectly inside the comment will keep it included - and its whitespace intact.

<!--[
/**
* Some copyright
*
*/
]-->

The alternative - we can edit HTMLmin.php to keep the comment:

Line 50:

foreach ($xpath->query('//comment()') as $comment) {
$val= $comment->nodeValue;
if( strpos($val,'[')!==0 && 
strpos(strtolower($val),'copyright')!==0 ){
$comment->parentNode->removeChild($comment);
}
}

Reply to this email directly or view it on GitHub: https://github.com/searchturbine/phpwee-php-minifier/issues/1#issuecomment-88138409 — Reply to this email directly or view it on GitHub https://github.com/searchturbine/phpwee-php-minifier/issues/1#issuecomment-88162985.

julkue commented 9 years ago

Yes but my problem is that the copyrights are in the HTML itself, so I would replace them with a regex first and store them to a temporary variable. After the minify I would need to add them again. Therefore I would need to know where to put them. A bit complex I think.

ztkemsley commented 9 years ago

Sure - so the logic you want is to keep all of your html comments that contain the word copyright? Perhaps a parameter set regex matches for comments to keep?

We already do have a system for identifying comments you want to keep:

<!--[
 /**
  * Some copyright
  *
  */
]-->

Can you explain why that is unworkable so i can understand?