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

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

Conversation

@ikatyang
Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Nov 8, 2018

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

@ikatyang

This comment has been minimized.

Copy link
Member Author

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)
);
}
});
}
};

@j-f1
j-f1 approved these changes Nov 8, 2018
@j-f1
j-f1 approved these changes Nov 8, 2018

@ikatyang ikatyang merged commit 9acb029 into prettier:master Nov 9, 2018

10 checks passed

ci/circleci: build_prod Your tests passed on CircleCI!
Details
ci/circleci: checkout_code Your tests passed on CircleCI!
Details
ci/circleci: test_prod_node4 Your tests passed on CircleCI!
Details
ci/circleci: test_prod_node9 Your tests passed on CircleCI!
Details
ci/circleci: test_prod_standalone Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 80%)
Details
codecov/project 97.03% (+0%) compared to fd8ec95
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details

@ikatyang ikatyang deleted the ikatyang:feat/html/treat-capital-element-as-custom-element branch Nov 9, 2018

@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.
Projects
None yet
3 participants
You can’t perform that action at this time.