-
Notifications
You must be signed in to change notification settings - Fork 29
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
Extending removeComments to keep only some custom comments #73
Comments
Thanks for the suggestion! It totally makes sense. It also made me think if such custom rules could come in handy in other modules. I created #75 for discussing that. I'd be happy to hear your thoughts about that. |
Any progress here? Because I could need this for Server-Side SSI, which is currently being stripped out. |
@SoftCreatR I can create a PR implementing the feature. |
That would be 👍 |
Just FYI: It works absolutely fine (at least for me and my special case). |
Currently, the
removeComments
options allows tofalse
)'all'
)<!--/?noindex-->
(using'safe'
)This works great for classic/standard projects, but is problematic in more advanced use cases, where some special comments are used in another framework to extend the HTML file later one. In these situations,
'all'
and'safe'
are not useful, as either all or at least the custom special comments are removed. However,false
is also impractical, as it keeps all kind of comments, not differentiating between development (should be removed) comments or special framework comments.For example,
vue-server-renderer
uses the<!--vue-ssr-outlet-->
comment to inject the compiled markup. Another example I have seen in the wild is KnockoutJS, which supports a so called containerless control flow, which uses comments like<!-- ko if : isEditable() -->Some markup<!-- /ko -->
.As a solution, I suggest to add another option. Allowing the user to provide a regular expression, working as a whitelist of comments to keep.
This shouldn't conflict with the existing
'all'
and'safe'
options, as we can always add<!--
to the regex to be more specific. So if someone wants to keep all comments that includeall
, it could also be written as<--.*?all
.The actual implementation could then be something like this:
'all'
and'safe'
can be assumed to be a regular expression, we shouldn't overwrite the option anymore.'all'
and'safe'
to their corresponding regular expression.'all'
can be seen as/^$/
(will only match an empty string/nothing)'safe'
is a combination of:/^<!--\/?noindex-->$/
isConditionalComment
, which uses already a regular expression (/<!--\[if/
) inside and only invoked/used by this single line./^<!--(\/?noindex|\[if.+?)-->$/
To keep it intuitive, I would also suggest to rename the option from
removeComments
tokeepComments
(andall
tonone
in correspondence). However, I won't suggest to do this before version 1.0, as this project is already a widely spread dependency.The text was updated successfully, but these errors were encountered: