You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some situations controlling how markup attribute values are formatted can be beneficial, especially when working with Liquid. Though I personally consider attribute values to expressed in a strict manner, this option is likely helpful in a lot of situations. The attributeValues formatting option introduces support for exactly this. This ruleset allows users to take reign and control of HTML attributes values and in addition will gracefully handle contained Liquid tokens infused within.
Goals
This option needs to facilitate multiple beautification options which directly pertain to how attribute values should be formatted in Markup languages. The inherited behaviour of PrettyDiff and Sparser here is a little problematic and changes applied for this enhancement require various refactors. The main goal here is provide stable enough processing and output for typical coding styles whereas the edge cases and chaotic projects, like that seen in the utter debauchery that is Shopify Dawn, will likely need some patches in order to handle otherwise despicable code structures.
Context
Introducing this option requires intercepting the lexing records constructed by Sparser. Refactoring the attribute lexer and tokenization approach of the markup lexer is essential. The attribute values also need to be walked and temporary reference generated before logic is passed to the various handlers in PrettyDiff.
Ruleset
The option will provide multiple beautification style choices. The initial rollout will include the following:
preserve
strip
collapse
wrap
There is consideration and room for advancement here, so introducing template specific beautification choices is likely to incur in the pre-release version or very soon after but for now will not be supported.
wrap-liquid
collapse-inline-preserve
Definition
The option will be available to markup and can be defined as followed:
The below examples showcase how the different formatting styles will output attribute values.
Preserve (default)
The preserve option will leave HTML attribute values intact, preserving the input provided.
Before Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
After Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
Strip
The strip option will strip newlines and equally distribute spacing by removing extraneous whitespace between entries from values and replacing them with a single space character.
Before Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
After Formatting
<divclass="one two three {% ifx %}four{% else %}five{% endif %} {{ some.object }} six seven"></div>
Wrap
The wrap option will apply indentation to attribute values if wrap limit has been exceeded. This option respects the inner contents of Liquid tokens and will not augment such expressions if detected. Indentation is applied for each whitespace separated character in the value sequence.
Below we assume wrap has been exceeded.
Before Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
After Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
Collapse
The collapse option will apply indentation to all attribute values. This option does not respect the inner contents of Liquid tokens and will apply forced indentation for each whitespace separated character in the value structure and any Liquid token encountered, for example:
Before Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
After Formatting
<divclass="one two three {% ifx %} four {% else %} five {% endif %} {{ some.object }} six seven"></div>
The text was updated successfully, but these errors were encountered:
Description
In some situations controlling how markup attribute values are formatted can be beneficial, especially when working with Liquid. Though I personally consider attribute values to expressed in a strict manner, this option is likely helpful in a lot of situations. The
attributeValues
formatting option introduces support for exactly this. This ruleset allows users to take reign and control of HTML attributes values and in addition will gracefully handle contained Liquid tokens infused within.Goals
This option needs to facilitate multiple beautification options which directly pertain to how attribute values should be formatted in Markup languages. The inherited behaviour of PrettyDiff and Sparser here is a little problematic and changes applied for this enhancement require various refactors. The main goal here is provide stable enough processing and output for typical coding styles whereas the edge cases and chaotic projects, like that seen in the utter debauchery that is Shopify Dawn, will likely need some patches in order to handle otherwise despicable code structures.
Context
Introducing this option requires intercepting the lexing records constructed by Sparser. Refactoring the attribute lexer and tokenization approach of the markup lexer is essential. The attribute values also need to be walked and temporary reference generated before logic is passed to the various handlers in PrettyDiff.
Ruleset
The option will provide multiple beautification style choices. The initial rollout will include the following:
preserve
strip
collapse
wrap
There is consideration and room for advancement here, so introducing template specific beautification choices is likely to incur in the pre-release version or very soon after but for now will not be supported.
wrap-liquid
collapse-inline-preserve
Definition
The option will be available to
markup
and can be defined as followed:Examples
The below examples showcase how the different formatting styles will output attribute values.
Preserve (default)
The
preserve
option will leave HTML attribute values intact, preserving the input provided.Before Formatting
After Formatting
Strip
The
strip
option will strip newlines and equally distribute spacing by removing extraneous whitespace between entries from values and replacing them with a single space character.Before Formatting
After Formatting
Wrap
The
wrap
option will apply indentation to attribute values if wrap limit has been exceeded. This option respects the inner contents of Liquid tokens and will not augment such expressions if detected. Indentation is applied for each whitespace separated character in the value sequence.Before Formatting
After Formatting
Collapse
The
collapse
option will apply indentation to all attribute values. This option does not respect the inner contents of Liquid tokens and will apply forced indentation for each whitespace separated character in the value structure and any Liquid token encountered, for example:Before Formatting
After Formatting
The text was updated successfully, but these errors were encountered: