简体   繁体   English

Jetbrains PhpStorm HTML缩进

[英]Jetbrains PhpStorm HTML indentation

It appears PHPStorm doesn't want to follow the code style I specified. 看来PHPStorm不想遵循我指定的代码样式。 Each time I format an HTML file, it collapses the indentation from this: 每次格式化HTML文件时,它都会折叠缩进:

<html>
    <head>
        bleh
    </head>
    <body>
        bleh
    </body>
</html>

to

<html>
<head>
<bleh>
    bleh
<bleh>
</head>
<body>
<bleh>
    bleh
<bleh>
</body>
</html>

"bleh" (being all the contained tags) are indented how they're suppose to. “bleh”(包含所有包含的标签)缩进了它们的假设。
I found the setting: File -> Settings -> Code Style -> HTML -> Other -> "Do not indent children of". 我找到了设置:文件 - >设置 - >代码样式 - > HTML - >其他 - >“不要缩进子项”。
That was filled with several tags which I have already removed (so the text field is empty). 那里面填充了几个已经删除的标签(因此文本字段为空)。
The settings are theoretically applied to the Project scheme which is the current scheme. 这些设置理论上适用于当前方案的项目方案。
However, I haven't fully grasped the concept of what these schemes are, so I may be missing something important. 但是,我还没有完全理解这些方案的概念,所以我可能会遗漏一些重要的东西。

Pictures: 图片:
http://snapshot.overloadproducts.com/7411c9d50e0b43edc76c1e625a38d61c http://snapshot.overloadproducts.com/5a74f83356572f3644a6d52bf2fa1f66 http://snapshot.overloadproducts.com/7411c9d50e0b43edc76c1e625a38d61c http://snapshot.overloadproducts.com/5a74f83356572f3644a6d52bf2fa1f66

Edit: Opened PHPStorm the next day, and it said the project file had been edited externally, and it needed to refresh. 编辑:第二天打开PHPStorm,它表示项目文件已在外部编辑,需要刷新。 Once it did, it was formatting correctly again. 一旦它完成,它再次正确格式化。
So somehow the settings file was out of sync and the settings window wasn't saving to the file. 因此,某些设置文件不同步,并且设置窗口未保存到文件中。
Still a bug in my opinion. 我认为还是一个错误。

Just go to Setting/preferences -> Editor -> Code Style -> HTML -> Other 只需转到Setting/preferences - > Editor - > Code Style - > HTML - > Other

Insert new line before: add body. 之前插入新行:添加正文。

Do not indent children of: clear all in this form. 不要缩小孩子:以这种形式清除所有内容。

ANSWER (ON EDIT): For an actual work around, try right clicking your document and clicking "Paste Simple". 答案(编辑时):要进行实际操作,请尝试右键单击文档并单击“粘贴简单”。 This will preseve the formatting of the text pasted on the clip-board. 这将预先设置粘贴在剪贴板上的文本的格式。 Not really a solution as such, but an appropriate workaround. 这不是一个真正的解决方案,而是一个合适的解决方法。

ORIGINAL: 原版的:

Did you end up getting an answer for this? 你最终得到了答案吗?

I have the same problem, and for the life of me can't fix it. 我有同样的问题,因为我的生活无法解决它。 This is really really annoying, especially seeing as the "preview" pane of what the code formatting should look like isn't accurate - it shows: 这真的很烦人,特别是看到代码格式应该是什么样的“预览”窗格是不准确的 - 它显示:

<div>
    <div>
        <p>
            Some comment from JetBrains.
        </p>
    </div>
</div>

... but when pasting in text from an editor, it gets reformatted to: ...但是当从编辑器粘贴文本时,它会重新格式化为:

<div>
<div>
<p>
Some comment from JetBrains.
</p>
</div>
</div>

Sorry for posting a comment in the answer section but I don't have 15 reputation. 很抱歉在答案部分发表评论,但我没有15个声望。

Right below the option "Do not indent children of:" you'll find the option "or if tag size more than" with a default value of 200. 在“不要缩进子项:”选项的正下方,您会找到选项“或标签大小超过”,默认值为200。

That means that for larger HTML-Files indentation will effectively be disabled. 这意味着对于较大的HTML文件,缩进将被有效禁用。 I have no idea why anyone would want that but the way to get rid of this (miss-)behaviour is to remove that value (just leave the field empty). 我不知道为什么有人会想要这个,但摆脱这个(miss-)行为的方法是删除该值(只是将该字段留空)。

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

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