Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ignore copyrights in HTML from compressing? #1

Open
julkue opened this issue Mar 31, 2015 · 5 comments
Open

How to ignore copyrights in HTML from compressing? #1

julkue opened this issue Mar 31, 2015 · 5 comments

Comments

@julkue
Copy link

julkue commented Mar 31, 2015

Hello,

my copyrights look like

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

How can I ignore those from compressing HTML?

@ztkemsley
Copy link
Contributor

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
Copy link
Author

julkue commented Mar 31, 2015

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

@ztkemsley
Copy link
Contributor

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:
#1 (comment)

Reply to this email directly or view it on GitHub #1 (comment).

@julkue
Copy link
Author

julkue commented Apr 1, 2015

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
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants