Skip to content

Conversation

@fisker
Copy link
Member

@fisker fisker commented Jan 18, 2020

Please DO NOT MERGE until we have consensus that this should be accepted.

Fixes: #6502

  • 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)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@fisker fisker force-pushed the lowercase-doctype branch from 79d16df to ca3918c Compare January 18, 2020 12:36
@lipis
Copy link
Member

lipis commented Jan 20, 2020

I'm down!

@thorn0
Copy link
Member

thorn0 commented Jan 20, 2020

It would be another incompatibility with XML. Why introduce it without a reason?

@fisker
Copy link
Member Author

fisker commented Jan 20, 2020

@thorn0 #6502 (comment)

@lipis
Copy link
Member

lipis commented Jan 20, 2020

xml requires uppercase?

@thorn0
Copy link
Member

thorn0 commented Jan 20, 2020

@alexander-akait
Copy link
Member

I think we should discuss about supporting xhtml (xml)

@thorn0
Copy link
Member

thorn0 commented Jan 22, 2020

How about lowercasing it only if it's the HTML5 doctype (<!doctype html>)?

@alexander-akait
Copy link
Member

alexander-akait commented Jan 22, 2020

@thorn0 Problem what some developers can use not fully html template (without doctype) and we can potential break code

@thorn0
Copy link
Member

thorn0 commented Jan 22, 2020

I mean lowercasing only in this one case, when doctype is <!doctype html>. If it contains something else (e.g. after html), it should be uppercase.

As far as I understand, <!DOCTYPE html> is meaningless from the XML point of view anyway because it doesn't include a link to DTD. It's only needed for the browser not to switch to a legacy mode, and browsers don't care about its case. So lowercasing it should not affect anything. Probably... :)

But also there is (or was, it's "no longer in active maintenance") a thing called Polyglot markup, a way to write markup compatible with both syntaxes at the same time, and it requires the doctype to be uppercase.

So after all, the safest option seems to be to keep the current behavior.

@fisker fisker changed the base branch from master to next February 14, 2020 11:31
@fisker fisker changed the title Print doctype in lowercase Print HTML5 doctype in lowercase Feb 14, 2020
@thorn0 thorn0 closed this Mar 22, 2020
@thorn0 thorn0 reopened this Mar 22, 2020
@thorn0 thorn0 changed the base branch from next to master March 22, 2020 21:13
@kydesnic
Copy link

I understand the concerns about merging this as is. This is the explicit change of the current behaviour.
But couldn't this be done with a new configuration option? If the default configuration value will produce the current result, the existing users will not be affected. But those, who want to change the behaviour, will be able to tune it.

@fisker fisker force-pushed the lowercase-doctype branch from 8e4b65b to 9781cfc Compare June 21, 2020 07:07
@fisker
Copy link
Member Author

fisker commented Jun 23, 2020

@kydesnic We don't add options.

Base automatically changed from master to main January 23, 2021 17:13
@sosukesuzuki sosukesuzuki mentioned this pull request Jul 20, 2022
23 tasks
@fisker fisker changed the base branch from main to next August 5, 2022 14:02
@fisker fisker force-pushed the lowercase-doctype branch from 9781cfc to 2cc228c Compare August 5, 2022 14:29
@fisker
Copy link
Member Author

fisker commented Aug 5, 2022

Can we include this in V3?

Copy link
Member

@JounQin JounQin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, prettier does not change the inputs but only prints, why it is changed here?

@fisker
Copy link
Member Author

fisker commented Aug 5, 2022

prettier does not change the inputs but only print

We change html tags to lowercase.

why it is changed here

Check original issue #6502

@JounQin
Copy link
Member

JounQin commented Aug 5, 2022

We change html tags to lowercase.

So the correct change to me should be keeping the input as-is instead.

@fisker fisker requested a review from sosukesuzuki August 6, 2022 04:09
@JounQin
Copy link
Member

JounQin commented Aug 6, 2022

@fisker It seems you disagree with my opinion here which follows https://prettier.io/docs/en/rationale.html#what-prettier-is-_not_-concerned-about and it is mentioned a lot of times by @thorn0 elsewhere.

Maybe I ask why we are not consistent here?

@fisker
Copy link
Member Author

fisker commented Aug 6, 2022

I don't talk.

@thorn0
Copy link
Member

thorn0 commented Aug 6, 2022

Prettier usually normalizes case-insensitive things: CSS property names, HTML tag names, JS hex numbers, etc. Often it's done by the parser. When something is syntactically case-insensitive, it means case is styling/formatting, which is what Prettier deals with. Of course, there aren't strict definitions of what "formatting", "linting", "transform", etc. are, so the debates about this stuff can be endless.

@JounQin
Copy link
Member

JounQin commented Aug 6, 2022

Of course, there aren't strict definitions of what "formatting", "linting", "transform", etc. are, so the debates about this stuff can be endless.

@thorn0

It makes sense to me. And then can we define what are considering as formatting into the policy on prettier's side in details? Otherwise it could still be confusing in the future.

For example, when the content is case-insensitive we usually print them in lowercase.

@thorn0
Copy link
Member

thorn0 commented Aug 6, 2022

can we define what are considering as formatting into the policy on prettier's side in details

I don't believe it's possible to come up with clear and satisfying definitions. It's all too complicated and full of tradeoffs. E.g., what are numeric separators in JS? Syntax or formatting? Are the two ways to make a code block in Markdown (fenced and indented) just two different styles for the same syntactic thing, so they should be normalized to one style? What about empty statements in JS? The general idea is kind of simple: "preserve the syntax and regenerate formatting from scratch (keeping some elements of the original formatting when practical)", but when it comes to defining the line between syntax and formatting, things become tricky. I don't think this boundary is formalizable. Decisions should be made on the case-by-case basis. 🤷‍♂️

Otherwise it could still be confusing in the future

I'd say it gets confusing mostly in bikesheddy cases like this doctype issue, where the practical value of doing it one way or another is really questionable.

@fisker fisker merged commit f8fff81 into prettier:next Aug 7, 2022
@fisker fisker deleted the lowercase-doctype branch August 7, 2022 17:13
@yoyo837
Copy link

yoyo837 commented Jul 15, 2023

#15096 Personally I want it to stay uppercase regardless of the standard, how do I control it from being converted to lowercase by prettier? Its performance in prettier 2.x is in line with my expectations, but recently I upgraded to 3.0 and it is not

@eligrey
Copy link

eligrey commented Sep 29, 2023

DOCTYPE is case sensitive in XML contexts. With this change, prettier no longer supports my XHTML.

@eligrey
Copy link

eligrey commented Sep 30, 2023

Re: @thorn0 #7391 (comment)

As far as I understand, is meaningless from the XML point of view anyway because it doesn't include a link to DTD. It's only needed for the browser not to switch to a legacy mode, and browsers don't care about its case. So lowercasing it should not affect anything. Probably... :)

Browsers care about the doctype case in XML contexts.

But also there is (or was, it's "no longer in active maintenance") a thing called Polyglot markup, a way to write markup compatible with both syntaxes at the same time, and it requires the doctype to be uppercase.

The 'polyglot' markup is and has been supported by all major browser engines (even Trident & EdgeHTML) for over a decade. It has use in some sites and frameworks (including many of my own).

@yoyo837
Copy link

yoyo837 commented Oct 1, 2023

Polyglot markup, doctype doc https://www.w3.org/TR/html-polyglot/#doctype Uppercase needed.

@Rock-n-Roll-CRC
Copy link

Are W3C standards a joke to you? If something works, why would you ever want to ruin it? Revert the changes concerning the <!DOCTYPE html> casing.

@atesgoral
Copy link

DOCTYPE is not an HTML tag. It's a preamble. "We lowercase all HTML tags" shouldn't have applied here.

@ProximaB
Copy link

ProximaB commented Aug 9, 2024

How to change that behavior?

@ptu14
Copy link

ptu14 commented Aug 19, 2024

From: https://html.spec.whatwg.org/multipage/syntax.html#the-doctype

A DOCTYPE must consist of the following components, in this order:

In other words, <!DOCTYPE html>, case-insensitively.
`

my proposal to add --doctype-case #16588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print <!doctype html> lowercase rather than uppercase