Page MenuHomePhabricator

Support <style scoped> as HTML element in wiki source
Closed, DeclinedPublic

Description

Enhancement request: Add <style scoped> to the set of HTML elements that can be used in wiki source. That would allow authors to specify styles for all child content of a particular part of a page (element). For example:

<div id="terms">
<style scoped>
ul: { display: table }
li: { display: table-row }
dfn: { display: table-cell }
p.def { display: table-cell }
</style>
<ul>
<li>
<dfn id="scoped">scoped</dfn>
<p.def>A attribute for the "style" element that allows you to include CSS rules within the body of an HTML document but scope those rules just to a particular portion of the document.</p>
</li>
</ul>
</div>


Version: 1.22.0
Severity: enhancement

Update 2016-03-04: Stalled due to unclear future of standards implementation/wide browser support. See discussion starting at https://phabricator.wikimedia.org/T52644#2088060
Update 2016-09-06: scoped attribute was removed from WHATWG HTML and csswg-drafts in May 2016

Details

Reference
bz50644

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 22 2014, 2:06 AM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz50644.
bzimport added a subscriber: Unknown Object (MLST).

<style scoped> is not yet supported by any browsers except for Firefox, and this attribute wouldn't degrade gracefully. It shouldn't be implemented anytime soon.

http://caniuse.com/#feat=style-scoped

(In reply to comment #1)

<style scoped> is not yet supported by any browsers except for Firefox,
http://caniuse.com/#feat=style-scoped

It's implemented in Chrome as well. There's a user option for enabling it. See the note at the bottom of that caniuse page.

and this attribute wouldn't degrade gracefully.

All CSS degrades pretty gracefully. How gracefully the actual user experience degrades depends on how the content's authored. The example I gave in the description will degrade from being displayed as a table to being displayed as a normal bulleted list.

(In reply to comment #2)

(In reply to comment #1)

<style scoped> is not yet supported by any browsers except for Firefox,
http://caniuse.com/#feat=style-scoped

It's implemented in Chrome as well. There's a user option for enabling it.
See the note at the bottom of that caniuse page.

Yeah, so in other words it's not supported unless someone enables it. That still means it's not supported.

(In reply to comment #2)

All CSS degrades pretty gracefully. How gracefully the actual user experience
degrades depends on how the content's authored. The example I gave in the
description will degrade from being displayed as a table to being displayed
as a normal bulleted list.

When one disregards the fact that your HTML and CSS are malformatted (<p.def>, trailing colons on selectors) and uses its fixed version in a browser which doesn't support <style scoped>, the styles from it are applies to all elements on the page, even ones outside the scope. So no, it does not degrade gracefully.

(In reply to comment #3)

in a browser which
doesn't support <style scoped>, the styles from it are applies to all
elements on the page, even ones outside the scope. So no, it does not degrade
gracefully.

Ah, yeah, you're right. Sorry for the noise -- I should have thought it through a little better.

It would be possible to emulate a scoped style for browser without support for scoped styles by changing the selectors to a specific element.

wikicode
<style>
table.wikitable > tr > th,
table.wikitable > * > tr > th {

background-color: #fee;

}
</style>

is converted to
<style scoped>
#mw-content-text table.wikitable > tr > th,
#mw-content-text table.wikitable > * > tr > th {

background-color: #fee;

}
</style>

Kulla awarded a token.Nov 24 2014, 5:41 PM
Danny_B added a subscriber: Danny_B.Mar 4 2016, 4:05 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 4 2016, 4:05 AM

Note that the experimental support was removed from Chrome a while back. Firefox is currently the only major browser to support <style scoped> natively: http://caniuse.com/#feat=style-scoped (which is a shame as it would solve so many problems!)

<style scoped> is actually now being considered for removal from the HTML Standard. See https://github.com/whatwg/html/issues/552#issue-128374405

So at this point, as the person who originally raised this issue, I’d be fine personally with it just being resolved/closed. In fact IMHO it rightly should be resolved/closed.

Should be closed only in case it is really removed from specs...

Explanation for being removed from Chrome:

It was partially implemented behind a flag, but was later retracted due to high code complexity.
https://groups.google.com/a/chromium.org/forum/#!searchin/blink-dev/scoped/blink-dev/R1x18ZLS5qQ/Bjuh_cENhlQJ

As long as standards spec discussion isn't clearly taking one direction (see ongoing WHATWG issue above) and preliminary support is removed from browsers like in Chrome/Blink, this task is going to put "stalled".

Volker_E changed the task status from Open to Stalled.Mar 4 2016, 10:29 PM
Volker_E updated the task description. (Show Details)

Just a factual note:

We are already inserting <style> tag inside the page <body> for ages...

Via CentralNotice.

It's not scoped (aka applies to the entire page, but only to that page where it is inserted).

Mozilla devs leaning toward removing <style scoped> support, see Bugzilla 1291515.

Volker_E updated the task description. (Show Details)Sep 6 2016, 9:07 PM

@Danny_B There's also a follow-up discussion on making style valid within body.

Anomie closed this task as Declined.Feb 7 2017, 5:18 PM
Anomie added a subscriber: Anomie.

<style scoped> is actually now being considered for removal from the HTML Standard. See https://github.com/whatwg/html/issues/552#issue-128374405
So at this point, as the person who originally raised this issue, I’d be fine personally with it just being resolved/closed. In fact IMHO it rightly should be resolved/closed.

Declining per this.

Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptFeb 7 2017, 5:18 PM