djLint icon indicating copy to clipboard operation
djLint copied to clipboard

[FEATURE] Title attribute without quotes

Open jayvdb opened this issue 4 years ago • 1 comments

  • [x] I've searched the issues
  • [x] I've read the docs

Feature Request

The following will be invalid HTML, as it is know-able the value will contain a space.

<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title={% trans 'Help & Support' %}></i>

Note trans is a synonym for translate, but the same problem can occur for

<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title={{ foo }}></i>

This could be expanded to apply to any html attribute. From the spec

The attribute value can remain unquoted if it doesn't contain spaces or any of " ' ` = < or > .

Two other attributes which are likely to contain spaces are value and placeholder, as used with input.

jayvdb avatar Oct 07 '21 13:10 jayvdb

This is quite important because without those quotes, the reformatter can make mistakes.

e.g.

<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title={% trans 'Support' %}></i>

becomes

<i class="fa fa-lg fa-question-circle"
   data-toggle="tooltip"
   title
   trans
   Support></i>

jayvdb avatar Oct 15 '21 05:10 jayvdb

@jayvdb It took a long time to get to this sorry :) I've made a few updates to the attribute parsing.

Attributes w/out quotes will become quoted. Valid attributes for this are single words, {{ tags }}, {% tags %}, or {% if|for %}{% endif %}.

Hopefully whoever uses an unquoted if/for statement know what they are doing :)

so for your examples,

<!-- in -->
<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title={% trans 'Support' %}></I>
<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title={{ foo }}></I>
<input checked=checked>
<!-- out -->
<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title="{% trans 'Support' %}"></I>
<i class="fa fa-lg fa-question-circle" data-toggle="tooltip" title="{{ foo }}"></I>
<input checked="checked">

christopherpickering avatar Nov 03 '22 10:11 christopherpickering

Awesome thanks!

jayvdb avatar Nov 03 '22 10:11 jayvdb

:tada: This issue has been resolved in version 1.19.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

christopherpickering avatar Nov 03 '22 12:11 christopherpickering