I'm going to assume the answer is 'no' here, but since I haven't actually found that answer, I'm asking.
我将在这里假设答案是'不',但由于我实际上没有找到答案,我问。
Quite basically, all I want to do is leave some HTML commenting in my files for 'author eyes only', simply to make editing the file later a much more pleasant experience.
基本上,我想做的就是在我的文件中留下一些HTML评论“仅限作者眼睛”,只是为了让以后编辑文件更加愉快。
<!-- Doing it like this -->
leaves nice clean comments but they show up when viewing the page source after output.
<! - 这样做 - >留下很好的干净注释,但是在输出后查看页面源时会显示它们。
I am using PHP, so technically I could <?PHP /* wrap comments in PHP tags */ ?>
which would prevent them from being output at all, but if possible I'd like to avoid all of the extra arbitrary PHP tagging that would be needed for commenting throughout the file. After all, the point of commenting is to make the document feel less cluttered and more organized.
我正在使用PHP,所以从技术上来说,我可以<?PHP / *在PHP标签中包装注释* /?>,这将阻止它们输出,但如果可能的话,我想避免所有额外的任意PHP标记将需要在整个文件中进行评论。毕竟,评论的目的是使文档更简洁,更有条理。
Is there anything else I could try or are these my best options?
还有什么我可以尝试或者这些是我最好的选择吗?
3 个解决方案
#1
2
No, anything in html will show up.
不,html中的任何内容都会显示出来。
You could, have a script that parses the code, and removes the comments, before it puts it up on the server, and then you would have the original, and the uncommented source.
您可以拥有一个解析代码的脚本,并在将注释放入服务器之前删除注释,然后您将拥有原始注释和未注释的源。
A tool to accomplish this: http://code.google.com/p/htmlcompressor/
完成此任务的工具:http://code.google.com/p/htmlcompressor/
#2
0
I guess these are your best options, yes, unless you run the entire HTML output through some sort of cleanup module before being sent to the client.
我想这些是你最好的选择,是的,除非你在发送到客户端之前通过某种清理模块运行整个HTML输出。
Anything not wrapped in server side syntax will will be output to the client if not modified on its way out (through template engines, for example). This goes for most (probably all) server side languages).
任何未包含在服务器端语法中的内容都将输出到客户端,如果没有在其出路时修改(例如通过模板引擎)。这适用于大多数(可能是所有)服务器端语言)。
#3
0
You could definitely write a parser that uses regex to strip out HTML comments, but unless you're already dealing with a roll-your-own CMS, most likely the work involved in this far outweighs the benefits of not using PHP comments as you suggested.
你绝对可以编写一个使用正则表达式来删除HTML注释的解析器,但除非你已经在处理自己动手的CMS,否则很可能所涉及的工作超过了你不建议使用PHP注释的好处。
#1
2
No, anything in html will show up.
不,html中的任何内容都会显示出来。
You could, have a script that parses the code, and removes the comments, before it puts it up on the server, and then you would have the original, and the uncommented source.
您可以拥有一个解析代码的脚本,并在将注释放入服务器之前删除注释,然后您将拥有原始注释和未注释的源。
A tool to accomplish this: http://code.google.com/p/htmlcompressor/
完成此任务的工具:http://code.google.com/p/htmlcompressor/
#2
0
I guess these are your best options, yes, unless you run the entire HTML output through some sort of cleanup module before being sent to the client.
我想这些是你最好的选择,是的,除非你在发送到客户端之前通过某种清理模块运行整个HTML输出。
Anything not wrapped in server side syntax will will be output to the client if not modified on its way out (through template engines, for example). This goes for most (probably all) server side languages).
任何未包含在服务器端语法中的内容都将输出到客户端,如果没有在其出路时修改(例如通过模板引擎)。这适用于大多数(可能是所有)服务器端语言)。
#3
0
You could definitely write a parser that uses regex to strip out HTML comments, but unless you're already dealing with a roll-your-own CMS, most likely the work involved in this far outweighs the benefits of not using PHP comments as you suggested.
你绝对可以编写一个使用正则表达式来删除HTML注释的解析器,但除非你已经在处理自己动手的CMS,否则很可能所涉及的工作超过了你不建议使用PHP注释的好处。