vitaly-t / decomment

:hammer: Removes comments from JSON, JavaScript, CSS, HTML, etc.
75 stars 21 forks source link

Ability to remove empty special comments? #10

Closed spacedawwwg closed 8 years ago

spacedawwwg commented 8 years ago

Is it possible to set up decomment to remove empty special comments?

use case is that I inject CSS and JS, but some pages do not have IE only assets.

I'd like to strip out the empty conditional comments if possible?

vitaly-t commented 8 years ago

At the moment this library can strip all <!--[if ...--> comments. Are you asking if it could remove only the ones that are empty?

spacedawwwg commented 8 years ago

Yes, just the empty ones.

On 30 Mar 2016, at 12:59, Vitaly Tomilov notifications@github.com wrote:

At the moment this library can strip all comments. Are you asking if it could remove only the ones that are empty?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/vitaly-t/decomment/issues/10#issuecomment-203396749

vitaly-t commented 8 years ago

Yes, it is possible, via option ignore. You would set it to a regular expression that defines non-empty conditional blocks, so only the empty ones will be removed.

But considering your case, are you actually removing anything else at all? Because if not, then you can do the same without decomment at all ;)

Well, sort of, beside all the extra useful options like space or trim ;)

vitaly-t commented 8 years ago

I've started with /<!\-\-\[if[\w\-]*\](?!\s+$).*\-\->/g here: https://regex101.com/ but it is not complete yet, you need to finish it yourself ;)

spacedawwwg commented 8 years ago

@vitaly-t Thank you.

I've got a "regex buddy" who helps me with these. I'll get him on the case for me (this is currently beyond my skill set).

vitaly-t commented 8 years ago

n.p. once you have the right regex, post it here, please, to share with others ;)