Comments (2)
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.
@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)
- Flag for multiple output files HOT 3
- file size limited to 2GB HOT 9
- Command line argument for adding extra content to the output file HOT 3
- Strangely slow performance on files with long strings HOT 1
- Line breaks are not removed HOT 10
- Feature: Browser-compatible version HOT 1
- Node incompatible HOT 4
- Add Changelog HOT 4
- Test on Node 20 HOT 1
- Err Require ESM HOT 3
- Provide an option to remove validation attributes: schemaLocation & noNamespaceSchemaLocation HOT 6
- Remove standalone attribute when no external markup declarations are used. HOT 3
- Please transform this in a typescript compatible version HOT 1
- removeUnusedNamespaces fails to recognise used namespaces in certain cases HOT 4
- removeUnusedNamespaces fails to recognise used namespaces in attributes HOT 1
- Add -o --output cli argument HOT 4
- Add options as CLI arguments HOT 4
- Removing comments will leave empty space between tags HOT 5
- Give error message, if flag is not correct HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minify-xml.