prettier / prettier/plugin-xml
Whitespace is incorrectly preserved when `xmlWhitespaceSensitivity` is set to `ignore`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 278
- Forks
- 46
- Avg merge
- 1m
- Merged PRs (30d)
- 13
Description
According to the XML specification, only \t, \n, \r, and (space character) are considered whitespace and are affected by the xml:space attribute. As it has been already raised in #768, the plugin used String#trim() to remove whitespace characters, affecting also other non-XML whitespace characters:
- U+00A0 No-Break Space
- U+1680 Ogham Space Mark
- U+2000 En Quad
- U+2001 Em Quad
- U+2002 En Space
- U+2003 Em Space
- U+2004 Three-Per-Em Space
- U+2005 Four-Per-Em Space
- U+2006 Six-Per-Em Space
- U+2007 Figure Space
- U+2008 Punctuation Space
- U+2009 Thin Space
- U+200A Hair Space
- U+2028 Line Separator
- U+2029 Paragraph Separator
- U+202F Narrow No-Break Space
- U+205F Medium Mathematical Space
- U+3000 Ideographic Space
- U+FEFF Zero Width No-Break Space
This issue has been fixed in 6170e95. However, the fix still affects most of the characters mentioned above due to the usage of the \s character class and the issue described originally in #768 still persists.
Probably the easiest way to fix the issue is to replace the \s character class with the (space character):
const content = chardata.TEXT.replaceAll(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the XML plugin implementation for xmlWhitespaceSensitivity and the current String#trim or \s-based handling. Reproduce the behavior with XML text containing tabs, line breaks, spaces, and the listed non-XML whitespace characters. Done means only tab, newline, carriage return, and space are trimmed when sensitivity is set to ignore.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100