plugin-xml icon indicating copy to clipboard operation
plugin-xml copied to clipboard

Text content is split around entities

Open adamalston opened this issue 1 year ago • 3 comments

Hi, I've encountered an issue with the plugin where text content is split around entities. It seems the formatter split's the content of p around the < entity.

Input (test.xml):

<outer><inner><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &lt; Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <ul><li>Some code &lt;
      <code>xsl: select="true()"</code>
      />.</li><li>Some code &gt;
      <code>xsl: select="false()"</code>
      />.</li></ul></inner></outer>

Command:

npx prettier --plugin=@prettier/plugin-xml --tab-width 4 --xml-whitespace-sensitivity "ignore" --print-width 1024 text.xml

Output:

<outer>
    <inner>
        <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            &lt;
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </p>
        <ul>
            <li>
                Some code
                &lt;
                <code>xsl: select="true()"</code>
                />.
            </li>
            <li>
                Some code
                &gt;
                <code>xsl: select="false()"</code>
                />.
            </li>
        </ul>
    </inner>
</outer>

Expected output:

<outer>
    <inner>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &lt; Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        <ul>
            <li>
                Some code &lt;
                <code>xsl: select="true()"</code>
                />.
            </li>
            <li>
                Some code &gt;
                <code>xsl: select="false()"</code>
                />.
            </li>
        </ul>
    </inner>
</outer>

Any suggestions or fixes would be appreciated. Thanks

adamalston avatar Feb 11 '24 00:02 adamalston

Some more information: this changed in version 3.3.1. The following XML is unchanged when formatted with 3.3.0:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:paragraph xmlns:w="http://example.com/">
  <w:text>&lt;foo&gt;</w:text>
</w:paragraph>

Switching to 3.3.1 and formatting results in:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:paragraph xmlns:w="http://example.com/">
  <w:text>
    &lt;
    foo
    &gt;
  </w:text>
</w:paragraph>

gebsh avatar Feb 12 '24 11:02 gebsh

Also seeing this issue, &amp; and other similar encoded characters cause new lines

nwcm avatar Feb 19 '24 05:02 nwcm

~~I created a PR(#771) to fix this problem.~~

The fix has some issues. Closing for now. Need more confirmation from the maintainer.

Sec-ant avatar Feb 27 '24 04:02 Sec-ant

@kddnewton, do you know when the version of the package will be bumped? Presumably, that needs to happen for the changes addressing this issue to land in the npm registry.

adamalston avatar Mar 23 '24 00:03 adamalston

Released in v3.4.0

kddnewton avatar Mar 29 '24 20:03 kddnewton