pmahend1 / PrettyXML

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

Some comments are lost after format #141

Closed sssutd closed 7 months ago

sssutd commented 7 months ago

Source doc:

<?xml version="1.0" encoding="utf-8" ?>
<!-- 1 -->
<a>
<!-- 2 -->
<b><!-- 3 --></b>
<!-- 4 -->
</a>
<!-- 5 -->

Format Document result:

<?xml version="1.0" encoding="utf-8"?>
<a>
  <!-- 2 -->
  <b>
    <!-- 3 -->
  </b>
  <!-- 4 -->
</a>

The first and the last comments are lost.

\ # Also, it would be nice if the option "Add Space Before Self Closing Tag" affected the <?xml ... ?> line and inserted a space before the closing ?>

pmahend1 commented 7 months ago

Thanks for reporting. I will fix them later today.

pmahend1 commented 7 months ago

Also, it would be nice if the option "Add Space Before Self Closing Tag" affected the <?xml ... ?> line and inserted a space before the closing ?>

Those are not really attributes, so that setting wont affect declaration. If you prefer to format this way, I can add a setting just for that.

sssutd commented 7 months ago

Many thanks for the lost comments fix. It works.

Also, it would be nice if the option "Add Space Before Self Closing Tag" affected the line and inserted a space before the closing ?>

Those are not really attributes, so that setting wont affect declaration. If you prefer to format this way, I can add a setting just for that.

I'm not sure what you mean by "attributes" here. The option name refers to "Closing Tag", not attributes. And stylistically the closing ?> looks similar to a closing tag /> Compare:

<a version="1.0"/>   # no space
<a version="1.0" />  # has space

<?xml version="1.0"?>  # no space
<?xml version="1.0" ?> # has space

Anyway, it is a very minor issue.

pmahend1 commented 7 months ago

<?xml version="1.0"?> is XML declaration, version here is version of XML. <a version="1.0"/> is an element. version here is an attribute. XML declaration and Element formatting have different rules for formatting. I do however understand what you are expecting. I can add a separate setting so that you can set to formatting XML declaration as <?xml version="1.0" ?>(space before ending of declaration), it does not have to overlap with addSpaceBeforeSelfClosingTag setting. Some people may want to format XML declaration without space. Making declaration wrapping with space may be unwanted for some where they only expect it for elements.

Hence I can add a setting add space before XML declaration end to facilitate your needs. Let me know if that works.

sssutd commented 7 months ago

Thanks. As I said, the issue is very minor. So I am happy with any solution you find appropriate.