When we create a html page comments like
<!-- Comment 1 -->
or inside php
// Comment2
are obvious from a right click of the page - Show code
How can i prevent that ?
CodePudding user response:
Hiding the comments inside is the answer.. Thanks everyone.
CodePudding user response:
Html comments will show on the HTML page but as long as you include your PHP comments in the <?php tag they won't show to the user
To leave html comments are normal if you check amazon.com's code you will see all the html comments but none php or whatever server lang they use so don't worry about html comments just don't include stupid stuff like your admin password or some revealing database schema stuff in the html comments.
if you still want to remove all the comments even html(vscode):
Easy way:
- Open extensions (ctrl-shift-x) * type in
remove commentsin the search box. * Install the top pick and read instructions.Hard way: * search replace(ctrl-h) * toggle regex on (alt-r). * Learn some regular expressions! https://docs.rs/regex/0.2.5/regex/#syntax
A simple
//.*will match all single line comments (and more ;D).#.*could be used to match python comments. And/\*[\s\S\n]*\*/matches block comments. And you can combine them as well://.*|/\*[\s\S\n]*\*/(|in regex means "or",.means any character,*means "0 or more" and indicates how many characters to match, therefore.*means all characters until the end of the line (or until the next matching rule))Of course with caveats, such as urls (
https://...) has double slashes and will match that first rule, and god knows where there are#in code that will match that python-rule. So some reading/adjusting has to be done!Once you start fiddling with your regexes it can take a lifetime to get them perfect, so be careful and go the easy route if you are short on time, but knowing some simple regex by heart will do you good, since regular expressions are usable almost everywhere. From https://stackoverflow.com/a/50575194/17239314
