Skip to content
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

[HTML] Format values of attributes with defined semantics #5482

Open
YarnSphere opened this issue Nov 14, 2018 · 0 comments
Open

[HTML] Format values of attributes with defined semantics #5482

YarnSphere opened this issue Nov 14, 2018 · 0 comments
Labels
lang:html Issues affecting HTML (and SVG but not JSX) type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@YarnSphere
Copy link

YarnSphere commented Nov 14, 2018

As briefly discussed in #5479, this issue targets the formatting of HTML attribute values that have defined semantics: for example, in regard to white spaces or commas.

An example of such an attribute is class, where class=" a b c " should be semantically equivalent to class="a b c". However, note that if the user is parsing element.className directly, this change is not safe. This could be controller via --html-whitespace-sensitivity or a new flag.

Solving this issue would first require some research effort into finding out which HTML attributes have values with semantics that allow Prettier to manipulate them. A list of all (most?) HTML attributes can be found at: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes

Implementation note: some attribute semantics are bound to the HTML element they are part of, e.g. the semantics of name are different between a button element and a meta element; class is a global attribute, so its semantics should be valid for all elements.

Prettier 1.15.2
Playground link

--parser html

Input (class, content, and accept examples):

<div class="a    b
    c d   "></div>
<meta content=" width=device-width  ,
  initial-scale=1.0,
               user-scalable=no"      />
<input type="file" accept=" image/gif  
                               , image/jpeg ">

Output (class, content, and accept examples):

<div
  class="a    b
    c d   "
></div>
<meta
  content=" width=device-width  ,
  initial-scale=1.0,
               user-scalable=no"
/>
<input
  type="file"
  accept=" image/gif  
                               , image/jpeg "
/>

Expected behavior (class, content, and accept examples):

<div class="a b c d"></div>
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" />
<input type="file" accept="image/gif, image/jpeg" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:html Issues affecting HTML (and SVG but not JSX) type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests

2 participants