morbac / xmltools

XML Tools plugin for Notepad++
GNU General Public License v3.0
257 stars 57 forks source link

Pretty print not adding proper tabs #201

Open theshoeshiner opened 1 year ago

theshoeshiner commented 1 year ago

Im using XMLTools 3.1.1.13

When I use the following line of XML:

<table><tr><th><span><span>t</span></span></th></tr></table>

And do pretty print, I get:

<table>
    <tr>
        <th>
            <span>
                <span>t</span>
</span>
        </th>
    </tr>
</table>
rdipardo commented 1 year ago

It looks like the above text was formatted by QuickXML. Browsing the code (which I can't debug because of issues with the Nuget packages), I see that ::writeEOL and ::writeIndentation are guarded by a condition that is false when text is encountered right before a closing tag:

https://github.com/morbac/xmltools/blob/de7606553ffcb305f6030a225e66f178fba6a28b/QuickXmlLib/QuickXml/src/XmlFormater.cpp#L289

This means QuickXML will not insert a newline between text and a closing tag. In the sample text above, text is adjacent to a closing tag inside the innermost span:

       closing tag
       ...........
       v
<span>t</span>
      ^...
      text

Using one of the other formatters, the result is the same or even worse:

xmltools-formatters-compared

All the above were formatted with the same options:

Auto-close tags             True
Ensure conformity           False
Apply xml:space="preserve"  False

Go to Plugins > XMLTools > Options to find them:

xmltools-format-options
theshoeshiner commented 1 year ago

@rdipardo Did you mean to say "SimpleXML"? Your screenshots match what I'm seeing. QuickXML actually produces correct indentation, SimpleXML produces the incorrect indentation that I initially encountered, and StringXML produces even worse indentation.

Im not sure why my installation was defaulting to SimpleXML, since on other machines a fresh install defaulted to QuickXML, but switching to QuickXML is a work-around for this specific issue.