Skip to content

feat(html): treat capital element as custom element#5395

Merged
ikatyang merged 2 commits intoprettier:masterfrom
ikatyang:feat/html/treat-capital-element-as-custom-element
Nov 9, 2018
Merged

feat(html): treat capital element as custom element#5395
ikatyang merged 2 commits intoprettier:masterfrom
ikatyang:feat/html/treat-capital-element-as-custom-element

Conversation

@ikatyang
Copy link
Copy Markdown
Member

@ikatyang ikatyang commented Nov 8, 2018

Fixes #5385

Custom element: keep it on its own line if both leading/trailing line breaks exist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • I’ve read the contributing guidelines.

Try the playground for this PR

@ikatyang ikatyang added this to the 1.15.2 milestone Nov 8, 2018
@j-f1
Copy link
Copy Markdown
Member

j-f1 commented Nov 8, 2018

What if someone writes <BODY> (etc.)? Are those still lowercased?

@ikatyang
Copy link
Copy Markdown
Member Author

ikatyang commented Nov 8, 2018

Yes, known html elements are lowercased in the parse step.

const lowerCaseIfFn = (text, fn) => {
const lowerCasedText = text.toLowerCase();
return fn(lowerCasedText) ? lowerCasedText : text;
};
const normalizeName = node => {
if (node instanceof Element) {
if (
!node.namespace ||
node.namespace === node.tagDefinition.implicitNamespacePrefix
) {
node.name = lowerCaseIfFn(
node.name,
lowerCasedName => lowerCasedName in HTML_TAGS
);
}
const CURRENT_HTML_ELEMENT_ATTRIBUTES =
HTML_ELEMENT_ATTRIBUTES[node.name] || Object.create(null);
node.attrs.forEach(attr => {
if (!attr.namespace) {
attr.name = lowerCaseIfFn(
attr.name,
lowerCasedAttrName =>
node.name in HTML_ELEMENT_ATTRIBUTES &&
(lowerCasedAttrName in HTML_ELEMENT_ATTRIBUTES["*"] ||
lowerCasedAttrName in CURRENT_HTML_ELEMENT_ATTRIBUTES)
);
}
});
}
};

@ikatyang ikatyang merged commit 9acb029 into prettier:master Nov 9, 2018
@ikatyang ikatyang deleted the feat/html/treat-capital-element-as-custom-element branch November 9, 2018 01:51
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants