Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: implement xmlWhitespaceSensitivity: 'preserve' #635

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

kendrickw
Copy link
Contributor

@kendrickw kendrickw commented Dec 13, 2022

Fixes #478

Add new suboption preserve to xmlWhitespaceSensitivity, to preserve significant whitespace within XML elements. This PR should address all the cases where significant white space exists.

Specifically:

  • spaces within string are preserved:

    // before and after prettier identical
    <v>some string    extra space</v>
    
  • string with space(s) at the beginning and/or end:

    // before and after prettier identical
    <v>
      some  string
    </v>
    
  • mixing elements within string literal is also supported, space(s) surrounding and within string literal will be preserved:

    before: <v> some  string<abc/>more string </v>
     after: <v> some  string<abc />more string </v>
    

See PR #479 for more detail

@kendrickw kendrickw changed the title feat: implement preserveSignificantWhitespace: 'preserve' feat: implement xmlWhitespaceSensitivity: 'preserve' Dec 13, 2022
@kddnewton
Copy link
Member

Nice work @kendrickw and thanks for your patience. I'll release this as part of the major release when prettier v3 ships.

@kddnewton kddnewton merged commit 53b3739 into prettier:main Dec 13, 2022
@kendrickw kendrickw deleted the feature/issue478 branch December 13, 2022 20:45
@maciej-panecki-wttech
Copy link

Great option, but can you updater the readme file as it outlines that option as available when it is not? Any ETA on v3?

PS. Great work, thx for this lib.

@kddnewton
Copy link
Member

The option is available on the main branch, so it reflects the current capability of the project. I unfortunately don't know the ETA on v3, I'm not involved in the main prettier/prettier development.

@dbrgn
Copy link

dbrgn commented Apr 17, 2023

Very useful, thanks @kendrickw for the implementation!

@kddnewton any chance for a new npm release?

@kddnewton
Copy link
Member

I released this under v3.0.0-alpha.0. It's under the next tag on npm because it depends on the prettier v3 alpha.

@kddnewton
Copy link
Member

Once v3 of prettier is released, I'll release this under v3 as well.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve spacing in string literal within element
4 participants