IntelliJ - "Reformat Code" 删除了文本中不必要的 HTML 换行符?

IntelliJ - Have "Reformat Code" remove unnecessary HTML newlines in text?

在 HTML 文件上使用 IntelliJ(和其他 JetBrains IDE)中的 "Reformat Code" 将在文本中添加换行符以确保文本不会超出右边距。我正在寻找的是能够将部分文本移回上一行,如果在上一行有 space。

例如,如果我原来有:

<p>
    This is some text that is fairly long and won't fit on a single line without going over the right margin.
</p>

重新格式化代码会产生类似的结果(假设右边距非常小):

<p>
    This is some text that is fairly long and
    won't fit on a single line without going
    over the right margin.
</p>

但是如果我删除一些文本:

<p>
    This is some text that
    won't fit on a single line without going
    over the right margin.
</p>

我想重新格式化代码以自动生成此结果:

<p>
    This is some text that won't fit on a
    single line without going over the right
    margin.
</p>

我查看了重新格式化代码的设置,但没有看到如何执行此操作。可能是 "Keep newlines" 选项之一,但删除这些选项似乎也删除了标签之间的换行符。有办法吗?

是的,Intellij 为 HTML 提供了名为 'Keep line breaks in text' 的代码样式选项。禁用该选项,然后重新格式化代码。