-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
rehype-remove-comments
: ability to preserve specific comments
#50
Comments
I like it, but I think I would call it rehype()
.use(rehypeRemoveComments, {
preserve: /# (block|endblock|include)/
})
rehype()
.use(rehypeRemoveComments, {
preserve(content) {
if (content.includes('# block')) {
return true
}
if (content.includes('# endblock')) {
return true
}
if (content.includes('# include')) {
return true
}
return false
}
}) |
Taking a step back, is an option needed at all? I'm not entirely opposed to adding an option, but it does feel very niche to me. Even the IE directive pass through could and potentially should be removed in the next major. |
Why not just go with
👍
I’m 👍 on this Q. Are there comments that you want to drop? Is turning off this plugin to keep all comments viable? |
@remcohaszing – good point, I already had the idea on just a regex instead of the array of them, but it seemed to me not too flexible if I ever wanted to preserve more cases of comments. The function is even better in terms of the readability! @ChristianMurphy, @wooorm – your approach on permanently disabling the HTML comments trimming is what I exactly had done before I decided to have the option I proposed in this issue, so let me add more context to this. The rehype is used in my repository with statically generated pages (using Astro), where the pages could be in different formats, depending on what's needed for a specific page: I could use only the non-HTML comments, but I'm not the only member of the team, and we don't want to have to remember about this rule each time we change something in the repo, and also I think it would be hard to establish some linting rule (or a rule for What do you guys think? |
Both the names Also passing either the
IMO it makes sense. HTML comments are part of the DOM and can have actual meaning. IIRC AngularJS used them? Terser also has this option ( |
Indeed.
True. And, preferably we’d support a string too. So that JSON config files are supported.
How?
A valid use case, but it seems to apply to JS/CSS/other code — I never see such copyright info in HTML comments. HTML has other ways to show that (
If people can write HTML comments and leak things, they could leak things in any other way: they could leak outside of comments.
Wouldn’t it make sense to use rehype to minify and remove all comments after nginx commands? I’m leaning on 👍 for such a feature, but I do wonder about the story for this use case. |
Personally I lean against accepting a string until this is something a user actually asks for. They can use JavaScript config files, but I think typically this is used programmatically.
Yeah, I think something like that. It has been a while.
I’ve seen such comments while viewing the HTML source of miscellaneous websites over the course of years. I don’t recall which websites exactly, but I know it happens. |
I think this is generally fair—to wait for users to request things—however, all current plugins (as far as I am aware) support the non-JS config so that users don’t have to use the JS config file.
This seems a bit iffy to me 🤔 Humans will see the content, so if there’s copyright on that content, you’d want that available to those humans too. Not just to programmars who view source? @didnotwant could you comment on my questions to you in #50 (comment)? About security and nginx commands? Thanks! |
I’m not judging, only observing. I wouldn’t choose for this either. The exact same thing can be said about JavaScript minifiers preserving such comments. |
This comment has been minimized.
This comment has been minimized.
My point is that it’s completely different: js/css minifiers have this option because OSS licenses (MIT etc) say that you must include the license in the code. So you import js/css from
I would love to see it because it seems so weird to me. 😅 |
@wooorm – thanks for the mention, I forgot to answer. Anyway:
Nope, security isn't the main thing here (primarily we use rehype for minification, though), but to me, removing all the unwanted comments (in HTML, but also in JS, or CSS) is not only about the performance, but also cleaning up possible comments containing e.g. business domain's knowledge – and sometimes particular types of comments should stay on prod, e.g. in minified JS there are the comments about author or licenses. But you're right – at the end of the day we (as developers) are the ones responsible for what's pushed to prod, so it's not my main reason as you wrote, but rather a nice-to-have tool which could ensure us that we don't have to remember about possible leaks from comments.
Minification happens during the build of the "dist", and the nginx commands are used to inject some, let's say organisation-wide, HTML fragments (replacing the HTML comments which I'd like to preserve) before serving the already built page to the client. |
OK, I think a PR for |
Initial checklist
Problem
On one of my projects I use nginx SSI Commands to include some company-wide HTML content to one of my pages – the injected HTML just replaces a specific set of HTML comments.
Currently the
rehype-remove-comments
only allows to setremoveConditional
flag so that the IE comments can be kept.I imagine that my use-case could be not the only one in the world – that's why I decided to file this issue.
Solution
My proposal is to add an option called
exclude
where one can pass an array of regular expressions matching specific content of HTML comments.Example usage in
.rehyperc
:But I'm not sure if such way of configuring it is acceptable in all possible usages of the plugin (I think that currently there's just a flag for a specific reason, e.g. it's easier to use the tools in CLI?).
I created a custom plugin for my repo (I believe as a temporary solution, if my idea is good enough to the maintainers of
rehype-minify
) which is mostly the same as the currentrehype-remove-comments
plugin, so let me share the code I prepared:Alternatives
I wasn't able to find any alternative plugins that could allow doing exactly what I expect in the description of the Problem.
If there are some and anyone knows them, please share with me!
The text was updated successfully, but these errors were encountered: