简体   繁体   English

PhpStorm HTML缩进属性

[英]PhpStorm HTML Indentation for attributes

For tags with lots of attributes I want to split every single attribute on a new line and it should indent with just a single tab when I press enter to invoke a new line. 对于具有大量属性的标记,我想在新行上拆分每个属性,当我按Enter键调用新行时,它应该只用一个标签缩进。

Following example output how I want to indent my attributes: 下面的示例输出我想要缩进我的属性:

<svg width="300px" height="150px">
    <ellipse class="fill-current" 
        cx="150" 
        cy="75" 
        rx="100"
        ry="75"
    />
</svg>

But PhpStorm automatically tries to indent all my lines to the current attribute: 但是PhpStorm会自动尝试将我的所有行缩进到当前属性:

<svg width="300px" height="150px">
    <ellipse class="fill-current"
             cx="150"
             cy="75"
             rx="100"
             ry="75"
    />
</svg>

I couldn't find any option in the Settings (Editor -> Code Style -> HTML) to change this behavior. 我在“设置”(编辑器 - >代码样式 - > HTML)中找不到任何选项来更改此行为。 Does anyone know a solution for this problem? 有谁知道这个问题的解决方案?

The reasoning behind this is because I use often custom tags in my HTML-Template. 这背后的原因是因为我经常在HTML模板中使用自定义标签。 Sometimes my own tags are pretty long and are combination of 2 or (in rare cases) 3 words and there it is handy to start all extra attributes on a new line and it shouldn't align on the end of the tag. 有时我自己的标签很长,并且是2或(在极少数情况下)3个单词的组合,并且在新行上启动所有额外属性并且它不应该在标签的末尾对齐是很方便的。 It is troublesome to indent the attributes on my own. 单独缩进属性很麻烦。 I want to automate it. 我想自动化它。

Try this: 尝试这个:

在此输入图像描述

This way I got the code formatted the way you wanted. 这样我就可以按照你想要的方式格式化代码。

Had a look for you. 好好看看你。

The red fixes your initial problem of having each attribute on a new line. 红色修复了在新行上使用每个属性的初始问题。 However, it does keep aligning with the first attribute of the element. 但是,它确实与元素的第一个属性保持对齐。 No option available in the HTML settings to have the first attribute also on a new line with a single tab indent. HTML设置中没有可用的选项,以便在具有单个制表符缩进的新行上具有第一个属性。

The other 2 colours: 其他2种颜色:

Green shows how it decides on before which elements to insert a new element. 绿色显示了它在插入新元素的元素之前如何决定。 Orange shows which are inline elements. 橙色显示哪些是内联元素。

If you would like a new line before certain inline elements, you might want to remove them from the inline elements option (orange) and insert them in the new line before option (green). 如果您想在某些内联元素之前添加新行,则可能需要从内联元素选项(橙色)中删除它们,并将它们插入选项(绿色) 之前新行中

phpstorm设置

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

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