@prettier/plugin-xml
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -9,2 +9,8 @@ # Changelog | ||
## [3.2.0] - 2023-08-08 | ||
### Added | ||
- Respect `xml:space="preserve"` as an override to the `xmlWhitespaceSensitivity` option. | ||
## [3.1.1] - 2023-07-14 | ||
@@ -226,3 +232,4 @@ | ||
[unreleased]: https://github.com/prettier/plugin-xml/compare/v3.1.1...HEAD | ||
[unreleased]: https://github.com/prettier/plugin-xml/compare/v3.2.0...HEAD | ||
[3.2.0]: https://github.com/prettier/plugin-xml/compare/v3.1.1...v3.2.0 | ||
[3.1.1]: https://github.com/prettier/plugin-xml/compare/v3.1.0...v3.1.1 | ||
@@ -229,0 +236,0 @@ [3.1.0]: https://github.com/prettier/plugin-xml/compare/v3.0.0...v3.1.0 |
{ | ||
"name": "@prettier/plugin-xml", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "prettier plugin for XML", | ||
@@ -31,3 +31,3 @@ "type": "module", | ||
"eslint": "^8.5.0", | ||
"eslint-config-prettier": "^8.0.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"husky": "^8.0.0", | ||
@@ -34,0 +34,0 @@ "jest": "^29.2.1", |
@@ -29,6 +29,37 @@ import * as doc from "prettier/doc"; | ||
function isWhitespaceIgnorable(node) { | ||
const { CData, Comment, reference } = node.children; | ||
function isWhitespaceIgnorable(opts, attributes, content) { | ||
// If the whitespace sensitivity setting is "strict", then we can't ignore the | ||
// whitespace. | ||
if (opts.xmlWhitespaceSensitivity === "strict") { | ||
return false; | ||
} | ||
return !CData && !reference && !hasIgnoreRanges(Comment); | ||
// If there is an xml:space attribute set to "preserve", then we can't ignore | ||
// the whitespace. | ||
if ( | ||
attributes && | ||
attributes.some( | ||
(attribute) => | ||
attribute && | ||
attribute.children.Name[0].image === "xml:space" && | ||
attribute.children.STRING[0].image.slice(1, -1) === "preserve" | ||
) | ||
) { | ||
return false; | ||
} | ||
// If there are character data or reference nodes in the content, then we | ||
// can't ignore the whitespace. | ||
if (content.children.CData || content.children.reference) { | ||
return false; | ||
} | ||
// If there are comments in the content and the comments are ignore ranges, | ||
// then we can't ignore the whitespace. | ||
if (hasIgnoreRanges(content.children.Comment)) { | ||
return false; | ||
} | ||
// Otherwise we can. | ||
return true; | ||
} | ||
@@ -455,6 +486,3 @@ | ||
if ( | ||
opts.xmlWhitespaceSensitivity !== "strict" && | ||
isWhitespaceIgnorable(content[0]) | ||
) { | ||
if (isWhitespaceIgnorable(opts, attribute, content[0])) { | ||
const fragments = path.call( | ||
@@ -461,0 +489,0 @@ (childrenPath) => printElementFragments(childrenPath, opts, print), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47589
1038