New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Rule: attributeChain #10
Comments
Mostly pertaining to #10 but include a ton of improvements overall.
Thinking about this option more and more and have decided to not go ahead. The intended default of When using |
Description
This is a Liquid specific beautification option and will controls how Liquid tags contained within HTML attributed should be formatted. The rule requires some considerable thought and does not want do too much handling.
Goals
Attribute chaining needs to respect the defined
wrap
limit but overrideforceAttribute
on inner contents when usinginline
. In cases wherewrap
is defined and the option is usinginline
with thecorrect
rule enabled (ie:true
), then Prettify should apply whitespace dashes to surrounding tag delimiters of the inner content it newlined in the chain that exceeded thewrap
length. Chaining should also respect preservation and input defined structures.Context
This option requires refactors and multiple augmentation and patches be applied in the Sparer lexing algorithm. New token types will be introduced here in order to know what type of token we are dealing with. The tokenization of attribute values will also undergo overhauls to ensure we are capturing connected Liquid and HTML type expression.
It's hard to predict the structure a user will employ. Because Liquid is novice appealing due to its simplicity, developers can be utterly fucking insufferable when infusing template logics into HTML attributes and as such this beautification rule will likely need to undergo edge-case testing in order to provide the best possible outcomes when reasoning with shitty code.
Sparser Types
This option will introduce new token type reference into Sparser. The new types will behave nearly identically to the standard lexing of Template tokens with differencing being the actual tokens pushed into the data structures. These new types will allow for tokens like
data-{{ some.object }}
to passed.template_attribute_start
A template tag within a HTML attribute that is not a singleton. When the
attributeChain
option is enabled and Prettify executes the beautification process this type value is used as a stack reference point to produce a chained result.Example
The
{% if x %}
token in the below example would be marked as atemplate_attribute_start
because it can be identified as a start type token given an ender exists.template_attribute_else
A template tag within a HTML attribute that can be identified as an else type conditional.
Example
The
{% elsif %}
and{% else %}
tokens in the below example would be marked as atemplate_attribute_else
because they can be identified as a else type tokens given they are contained within conditional typesif
andunless
tags. This type value is important for beautification handling as depending on defined options likeattributeChain
,forceAttribute
,wrap
and/orcorrect
then a token type value oftemplate_attribute_else
may be used to separate contents onto newlines.template_attribute_end
A template tag within a HTML attribute that can be identified as an ender type.
Example
The
{% endif %}
token in the below example would be marked as atemplate_attribute_end
because it can be identified as a ender type token given that a start type exists.Ruleset
The option will provide multiple beautification style choices. The initial rollout will include the following:
preserve
collapse
inline
There is consideration and room for advancement here, so the potential to extends these choices is likely.
Definition
The option will be available to
markup
and can be defined as followed:Examples
Preserve (default)
Preserve strips extraneous whitespace and newlines if they exceed the defined
preserveLine
limit but it will leave the overall structure intact. Notice how in the below example, the only difference before and after formatting is the extraneous whitespace.Inline
Notice how before formatting the contents of the tag block are separated onto new lines whereas after formatting the contents are chained together.
Collapse
Collapse will newline the contents of the tag block. Notice how before formatting contents are expressed on a single line, whereas after formatting content is forced onto new lines.
The text was updated successfully, but these errors were encountered: