有没有办法阻止 Eclipse (3.7) 弄乱的内容?标签?

发布于 2024-12-08 18:34:51 字数 808 浏览 0 评论 0原文

如果我使用属性视图在 XML 模式中编写多行文档,它会创建 标记来包含它。

每当我格式化文件(CTRL + SHIFT + F)时,除第一行之外的所有行都会缩进,有时由于这种缩进而被换行。

这种缩进和换行实际上破坏了从文件生成漂亮文档的所有努力。特别是如果我想记录允许值的表。

格式之前:

<xsd:documentation>1st line of comment
2nd line is indented and also wrapped as it exceeds the max line length setting.
3rd line is just indented.
</xsd:documentation>

格式之后:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line 
    length setting.
    3rd line is just indented.
</xsd:documentation>

首选项 -> 中的“格式评论”选项XML-> XML 文件 ->编辑器不帮助缩进。在同一首选项页面上增加“线宽”可以修复换行,但我真的希望编辑器不要格式化我的文档元素的内容。

If I write multi-line documentation in an XML schema using the properties view it creates <xsd:documentation> tags to contain it.

Whenever I format the file (CTRL+SHIFT+F) all lines but the first are indented and sometimes wrapped due to this indentation.

This indentation and wrapping effectively ruins every effort of generating a nice looking documentation from the file. Especially if I want to document a table of allowed values.

Before format:

<xsd:documentation>1st line of comment
2nd line is indented and also wrapped as it exceeds the max line length setting.
3rd line is just indented.
</xsd:documentation>

After format:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line 
    length setting.
    3rd line is just indented.
</xsd:documentation>

The "Format comments" option in Preferences -> XML -> XML files -> Editor does not help with the indentation. Increasing "Line width" on the same preferences page fixes wrapping but I really want the editor to NOT format my the contents of my documentation elements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

红颜悴 2024-12-15 18:34:51

您可以将 xml 属性 xml:space="preserve" 添加到 xsd:documentation 来告知必须保留空格。例如:

<xsd:documentation xml:space="preserve" >1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>

You could add an xml atribute xml:space="preserve" to xsd:documentation to tell that spaces must be preserved. For example:

<xsd:documentation xml:space="preserve" >1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>
迷路的信 2024-12-15 18:34:51

“格式注释”选项适用于 XML 注释:

<!-- comment -->

这就是它不能按您希望的方式工作的原因。

我不明白将“线宽”选项设置为 max(在版本 3.7 中为 999)时遇到什么问题。

如果您的 XML 是:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>

那么将“线宽”设置为 999 并且格式设置不会更改您的内容。不幸的是,没有没有选项可以关闭宽度检查(例如将“线宽”设置为 0)。

编辑:
似乎当您使用

<root>
    <documentation><![CDATA[
                1st line of comment

                2nd line is indented and also wrapped as it exceeds the max line length setting.

                3rd line is just indented.
        ]]></documentation>
</root>

"Format comments" option is for XML comments:

<!-- comment -->

That's why it's not working as you wish.

I do not understand what problem are you facing with setting "line width" option to max (in version 3.7 it is 999).

If your XML is:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>

Then setting "line width" to 999 and formatting does not change your content. Unfortunately there is no option to turn width checking off (for example to set "line width" to 0).

edit:
it seems that when you use <![CDATA[, Eclipse is not formating the content (at least indentation and line wrapping), example:

<root>
    <documentation><![CDATA[
                1st line of comment

                2nd line is indented and also wrapped as it exceeds the max line length setting.

                3rd line is just indented.
        ]]></documentation>
</root>
流绪微梦 2024-12-15 18:34:51

尝试像这样使用它:

<xsd:documentation><![CDATA[ 1st line of comment
2nd line is indented and also wrapped as it exceeds the max line 
length setting.
3rd line is just indented.]]></xsd:documentation>

但是,

<?xml version="1.0" encoding="UTF-16"?>

如果您还没有使用它,请尝试在您的文件中进行设置。 xml 中的新行在 ASCII 和 UTF-16 之间可能会出现问题

Try using it like this:

<xsd:documentation><![CDATA[ 1st line of comment
2nd line is indented and also wrapped as it exceeds the max line 
length setting.
3rd line is just indented.]]></xsd:documentation>

But ALSO , try to set

<?xml version="1.0" encoding="UTF-16"?>

in your file, if you are not already using it. New lines in xml can be problematic between ASCII and UTF-16

明月夜 2024-12-15 18:34:51

设置选项“在具有 PCDATA 内容的标签中保留空格”。

Set the option "Preserve whitespace in tags with PCDATA content".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文