简体   繁体   English

在PhpStorm中打开和关闭HTML标签时添加自动注释

[英]Add automatic comments upon opening and closing a HTML tag in PhpStorm

I want to add HTML comments proceeding each <div class=""> / <div id=""> and their respective </div> 's. 我想在每个<div class=""> / <div id="">及其各自的</div>添加HTML注释。

For example, say I have a <div class="main-container"> , I want a comment right after it to be <!-- Start of .main-container --> 例如,假设我有一个<div class="main-container"> ,我想在它之后发表评论<!-- Start of .main-container -->

And then after its </div> I want a <!-- End of .main-container --> 然后在</div>我想要一个<!-- End of .main-container -->

An example of what everything would look like: 一切都是这样的例子:

<div id="container"> <!-- Start of #container -->
    <div class="container-text"> <!-- Start of .container-text -->
        <h2> Foo </h2>
    </div> <!-- End of .container-text -->
</div> <!-- End of #container -->

Is there any way to automate this with PhpStorm? 有没有办法用PhpStorm自动化这个? I can't figure it out, any help will be greatly appreciated, thank you in advance. 我无法弄清楚,任何帮助将不胜感激,谢谢你提前。

Yes and No at the same time. 是和否同时。

Option 1: Create and use custom Live Template where you can have any text/code you want. 选项1:创建和使用自定义实时模板 ,您可以在其中获得所需的任何文本/代码。 For example: 例如:

<div id="$NAME$"> <!-- Start of #$NAME$ -->
    $END$
</div> <!-- End of #$NAME$ -->

Option 2: If you are using Emmet .. it has an option (a filter in Emmet terms) to add closing comment. 选项2:如果您正在使用Emmet ..它有一个选项(Emmet术语中的过滤器)来添加结束注释。

That's where "no" part comes in: 1) only closing comment and 2) it will be placed on new line (depends on your code formatting settings, I guess) and have a bit different style: 这就是“不”部分的来源:1)只关闭评论和2)它将被放置在新行上(取决于你的代码格式设置,我猜)并且有一点不同的风格:

<div class="container"></div>
<!-- /.container -->

Such option is available at Settings/Preferences | Editor | Emmet | HTML --> Comment tags Settings/Preferences | Editor | Emmet | HTML --> Comment tags提供了此Settings/Preferences | Editor | Emmet | HTML --> Comment tags Settings/Preferences | Editor | Emmet | HTML --> Comment tags

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM