pmahend1 / PrettyXML

Pretty XML is a XML Formatter extension for Visual Studio Code
MIT License
27 stars 17 forks source link

Suppress Replacing of Special Characters in Attribute Values #131

Closed christopher-fabian closed 10 months ago

christopher-fabian commented 11 months ago

Hi,

Pretty XML replaces special characters in attribute values for e.g. '>' / '<' automatically with '>' / '<'. We don't want this replacing in our team but there is no setting for turning this behaviour off. Is there any chance that you implement a setting for this purpose in a future release?

Best regards

pmahend1 commented 10 months ago

Hello,

Escaping those characters are per XML standards. Just to confirm the special characters you are concerned about are > and < only, right? I will see if it can be implemented though. Could you please provide couple of sample XMLs to test?

christopher-fabian commented 10 months ago

Hi @pmahend1 ,

FYI: In our cases the XMLs are UI-Views and the underlying framework is using some kind "expression binding". The content of the files e.g. look like this:

<View>
  <Content>
    <Label text="{i18n>LabelText}" />
    <Input id="Input1"
           value="{service>description}" />
  </Content>
</View>

After XML prettify it looks like this and the expression binding is no longer working.

<View>
  <Content>
    <Label text="{i18n&gt;LabelText}" />
    <Input id="Input1"
           value="{service&gt;description}" />
  </Content>
</View>

The default "Format Document" of VS Code is not escaping > and < perhaps due to such cases.

Best regards

pmahend1 commented 10 months ago

Thanks for confirming. I will look into it for adding an option

pmahend1 commented 10 months ago

@christopher-fabian I am in the process of adding that replacement. Do you have an example where < is part of an attribute value. As soon as I try to add it ,XML becomes invalid. I was able to use your above example to work on > replacement.

christopher-fabian commented 10 months ago

Hi @pmahend1 ,

oh you're right, that seems like a case that will never happen cause it invalidates the XML anyway. This probably doesn't need any further attention.

Best regards

pmahend1 commented 10 months ago

@christopher-fabian So for now, we just want to unescape > characters in attribute values, right? I can release it later today.

christopher-fabian commented 10 months ago

This would be enough for me, thank you! 👍

pmahend1 commented 10 months ago

Addressed with https://github.com/pmahend1/PrettyXML/pull/132