在IntelliJ IDEA中重新格式化混合内容XML

Ing*_*gel 3 xml reformat intellij-idea

我想阻止IDEA在某些元素周围插入换行符,类似于HTML格式,其中某些元素(如<b>)保持内联.

我有一个带有DTD的XML方言,它声明了混合内容.

DTD:

<!ELEMENT mixed (#PCDATA|inline)*>
<!ELEMENT inline #PCDATA>
Run Code Online (Sandbox Code Playgroud)

XML文件:

<mixed>
  Some text with <inline>inline elements</inline>
  and a line break.
</mixed>
Run Code Online (Sandbox Code Playgroud)

当我重新格式化XML文件时,IDEA会将其转换为

<mixed>
  Some text with 
  <inline>inline elements</inline>
  and a line break.
</mixed>
Run Code Online (Sandbox Code Playgroud)

我查看了Code style-> XML-> Other的所有选项."保留空白"选项限制性太强,因为我希望IDEA打破长线.

Eug*_*mov 6

在IDEA 13中,您可以使用新的Formatter Control功能来禁用所选代码行的自动形式.要启用此功能,您应在项目设置中标记以下复选框:

格式化程序控制设置

然后在注释中插入选定的标记,以划分不应由重新格式化代码工具格式化的代码片段,例如:

<root>
    <!-- @formatter:off -->
    <mixed>
        Some text with <inline>inline elements</inline>
        and a line break.
    </mixed>
    <!-- @formatter:on -->

    <mixed>
        Some text with
        <inline>inline elements</inline>
        and a line break.
    </mixed>
</root>
Run Code Online (Sandbox Code Playgroud)

不幸的是,在以前版本的IDEA中没有这样的功能,在这种情况下,我唯一知道的选项是手动格式化代码而不使用重新格式化代码工具.