Xavalon / XamlStyler

Visual Studio extension to help format your XAML source code
Apache License 2.0
1.17k stars 128 forks source link

Unexpected results with <elements> in text #454

Closed Jay-o-Way closed 8 months ago

Jay-o-Way commented 8 months ago

Describe the bug When having some text-related elements in a paragraph, the spaces and newlines before and after the elements are changed in a bad way.

To Reproduce Steps to reproduce the behavior:

  1. When formatting text in a \ that contains elements, like Bold or Hyperlink
  2. Spaces and newlines are bad

Expected behavior

Screenshots image

External Configuration

Version Info (please complete the following information):

Additional context I believe Visual Studio also has a habit of messing with these spaces and/or newlines. Might wanna reach out to that team, if possible?

grochocki commented 8 months ago

Please take a look at this section of the wiki on how we handle whitespace. There is this concept of "significant whitespace" in XAML that we need to maintain when formatting. If you are mixing inline-level flow content elements with other text (as in your example), you will want to specify xml:space="preserve" to preserve whitespace properly.

Jay-o-Way commented 8 months ago

You're right, that does the trick! Thanks! Please add a few words to the wiki text that this means to add the attribution to the XAML element and that it's not a setting for XamlStyler.

Besides that - Note that

newlines will not be added to \ if it is immediately followed by another element

is different then actively removing spaces.

grochocki commented 8 months ago

Glad that worked! The note on runs is specifically about back-to-back run elements. Anything more than that, and you should really use xml:space="preserve" to preserve intended whitespace. Updated wiki text to help clarify:

Please note that if you are mixing inline-level flow content elements with other text, you may need to specify xml:space="preserve" on the parent element in XAML to preserve whitespace properly.