Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Some significant whitespace is inserted in "xmlWhitespaceSensitivity: ignore" mode #138

Closed
sbidoul opened this issue Nov 1, 2020 · 7 comments

Comments

@sbidoul
Copy link

sbidoul commented Nov 1, 2020

Assume the following xml file:

<test>

   <field name="report_name">event_third_party.template_event_third_party_summary</field>

   <field name="report_file">event_third_party.template_event_third_party_summary</field>

</test>

In xmlWhitespaceSensitivity: ignore mode, signficant whitespace is sometimes inserted to cut long lines, so we get:

<test>
    <field name="report_name">
        event_third_party.template_event_third_party_summary
    </field>
    <field name="report_file">
        event_third_party.template_event_third_party_summary
    </field>
</test>

For our application, the inserted space in field elements is significant.

In strict mode the issue does not occur, but then most automatic indenting is disabled.

My feeling is that, in ignore mode, the text content of an element should never be modified as soon as there is a non-whitespace character in it.

@sbidoul sbidoul changed the title In xmlWhitespaceSensitivity: ignore some significant whitespace is inserted Some significant whitespace is inserted in "xmlWhitespaceSensitivity: ignore" mode Nov 1, 2020
@kddnewton
Copy link
Member

Can you clarify what you mean by your last sentence? I'm not clear on what your suggested behavior would look like. Also could you give an example of what it would mean?

@sbidoul
Copy link
Author

sbidoul commented Nov 1, 2020

In the example I gave, the result should look like this:

<test>
    <field name="report_name">event_third_party.template_event_third_party_summary</field>
    <field name="report_file">event_third_party.template_event_third_party_summary</field>
</test>

In other words, I think plugin-xml should have a mode where text nodes containing non-whitespace are never modified, while allowing reformating of whitespace-only text nodes. My impression is that this could be the behaviour of the xmlWhitespaceSensitiveity=ignore mode, but that could be another mode.

@kddnewton
Copy link
Member

I don't think we can really make that option a reality. The issue is that it completely depends on the schema, which prettier at the moment has no way of understanding. Some users want some of these nodes modified and some not.

I think the best I can offer in this case is to make use of ignore ranges, as in:

<test>
  <!-- prettier-ignore-start -->
  <field name="report_name">event_third_party.template_event_third_party_summary</field>
  <field name="report_file">event_third_party.template_event_third_party_summary</field>
  <!-- prettier-ignore-end -->
</test>

As a side note, do you have a published XSD schema somewhere where you have the whitespace rules listed? Or maybe a xml:space attribute somewhere? I'm trying to figure out where I would be able to determine that something is whitespace-significant

@sbidoul
Copy link
Author

sbidoul commented Nov 10, 2020

@kddeisz there must be a misunderstanding.

I totally agree that determining if a node containing only white space is significant or not requires xml:space (and possibly access to the schema to obtain its value, which is out of scope for this tool).

That is not what I am asking for.

To clarify, I found a nice description of different types of white space in XML at https://www.liquid-technologies.com/XML/Whitespace.aspx, and I copy the relevant picture here for clarity.

image

What prettier/plugin-xml needs is a mode where it allows itself to reformat red and blue white space, while never modifying green whitespace.

@sbidoul
Copy link
Author

sbidoul commented Jan 26, 2021

@kddeisz would you reconsider, given my previous comment ?

@kddnewton
Copy link
Member

kddnewton commented Jan 26, 2021 via email

@sbidoul
Copy link
Author

sbidoul commented Jan 26, 2021

I don't know if/when I'll be able to do a PR. In the meantime could we reopen the issue to track this enhancement request ?

What do you recommend: updating the behavior of xmlWhitespaceSensitiveity=ignore/strict or add a third option ?

len-foss pushed a commit to acsone/acsoo that referenced this issue May 28, 2021
…not break data

Files are prettier when formatted with the 'ignore' mode,
but it breaks Odoo/Python data by introducing significant whitespace.
See prettier/plugin-xml#138
sbidoul pushed a commit to acsone/acsoo that referenced this issue Jun 4, 2021
…not break data

Files are prettier when formatted with the 'ignore' mode,
but it breaks Odoo/Python data by introducing significant whitespace.
See prettier/plugin-xml#138
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants