Giter VIP home page Giter VIP logo

Comments (2)

kristian avatar kristian commented on August 31, 2024

Currently minify-xml does not consider the xml:space="preserve" attribute, when removing whitespace between tags. I even think this should be respected even if removeWhitespace is set to true. Thus I consider this a good first issue! However as according to the XML namespace spec. [1] the xml:space attribute is not mandatory and acts as an intent, thus minify-xml still acts according to spec. and I would like to deal with this issue as an enhancement, rather than a bug.

Let me see what I can do, maybe until end of week. Feel free to suggest any PR before that.

Thanks for filing this issue!

[1] https://www.w3.org/TR/xml-names/

from minify-xml.

kristian avatar kristian commented on August 31, 2024

@tiholic turns out, due to the regexp-based nature of minify-xml this one is again not possible to do fully spec. compliant. I have added basic support for this with f4f3626 and version 3.3.1. I decided to not use the removeWhitespaceBetweenTags flag, but the trimWhitespaceFromTexts and collapseWhitespaceInTexts, as they have been non-spec. compliant beforehand and need to be enabled explicitly. The limitation comes in when tags are used inside of elements with a xml:space declaration. Thus:

<tag xml:space="preserve">  hello  <br/>  world   </tag>

With options:

{
    "removeWhitespaceBetweenTags": false,
    "considerPreserveWhitespace": true,
    "trimWhitespaceFromTexts": true,
    "collapseWhitespaceInTags": true
}

Should result in the same output, so:

<tag xml:space="preserve">  hello  <br/>  world   </tag>

However, due to regular expressions have no knowledge about the DOM, it will actually result in:

<tag xml:space="preserve">  hello  <br/>world</tag>

This limitation cannot be overcome with the current regular expression-based engine of minify-xml. I am planning a 4.0 release of minify-xml which will switch from using regular expressions, to a parser-based approach. With that, more spec. compliant minifications will get possible.

However I hope adding basic support for considering the xml:space and pre tags satisfies your use case. With the options listed above (so removeWhitespaceBetweenTags false and trimWhitespaceFromTexts & collapseWhitespaceInTags true), the minification should turn out as you expected them.

Hope this helps!

from minify-xml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.