Skip to content

Commit 62661c5

Browse files
committed
[css-syntax] Add an "Environment encoding" concept (resolve an open issue.)
1 parent 36cd802 commit 62661c5

2 files changed

Lines changed: 92 additions & 31 deletions

File tree

css-syntax/Overview.html

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ <h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class
7272
Error Handling</a></ul><li><a href=#tokenizing-and-parsing><span class=secno>3</span>
7373
Tokenizing and Parsing CSS</a><ul class=toc><li><a href=#parsing-overview><span class=secno>3.1</span>
7474
Overview of the Parsing Model</a><li><a href=#input-byte-stream><span class=secno>3.2</span>
75-
The input byte stream</a><li><a href=#input-preprocessing><span class=secno>3.3</span>
75+
The input byte stream</a><li><a href=#environment-encoding><span class=secno>3.3</span>
76+
Environment encoding</a><ul class=toc><li><a href=#environment-encoding-at-import><span class=secno>3.3.1</span>
77+
<span class=css data-link-type=maybe title=@import>@import</span> rules</a><li><a href=#environment-encoding-html><span class=secno>3.3.2</span>
78+
HTML</a><li><a href=#environment-encoding-xml><span class=secno>3.3.3</span>
79+
XML</a></ul><li><a href=#input-preprocessing><span class=secno>3.4</span>
7680
Preprocessing the input stream</a></ul><li><a href=#tokenization><span class=secno>4</span>
7781
Tokenization</a><ul class=toc><li><a href=#token-diagrams><span class=secno>4.1</span>
7882
Token Railroad Diagrams</a><li><a href=#tokenizer-definitions><span class=secno>4.2</span>
@@ -418,12 +422,7 @@ <h3 class="heading settled heading" data-level=3.2 id=input-byte-stream><span cl
418422
<p class=note> Note: This mimics HTML <code>&lt;meta&gt;</code> behavior.
419423

420424
<li>
421-
Otherwise, <a data-link-type=dfn href=#get-an-encoding title="get an encoding">get an encoding</a> for the value of the <code>charset</code> attribute on the <code>&lt;link&gt;</code> element or <code>&lt;?xml-stylesheet?&gt;</code> processing instruction that caused the style sheet to be included, if any.
422-
If that does not return failure,
423-
use the return value as the fallback encoding.
424-
425-
<li>
426-
Otherwise, if the referring style sheet or document has an encoding,
425+
Otherwise, if an <a data-link-type=dfn href=#environment-encoding0 title="environment encoding">environment encoding</a> is provided by the referring document,
427426
use that as the fallback encoding.
428427

429428
<li>
@@ -435,13 +434,49 @@ <h3 class="heading settled heading" data-level=3.2 id=input-byte-stream><span cl
435434
<p class=note> Note: the <a data-link-type=dfn href=#decode title=decode>decode</a> algorithm lets the byte order mark (BOM) take precedence,
436435
hence the usage of the term "fallback" above.
437436

438-
<p class=issue id=issue-ead8fa31><a class=self-link href=#issue-ead8fa31></a>
439-
Anne says that steps 3/4 should be an input to this algorithm from the specs that define importing stylesheet,
440-
to make the algorithm as a whole cleaner.
441-
Perhaps abstract it into the concept of an "environment charset" or something?
437+
<h3 class="heading settled heading" data-level=3.3 id=environment-encoding><span class=secno>3.3 </span><span class=content>
438+
Environment encoding</span><a class=self-link href=#environment-encoding></a></h3>
439+
440+
<p>Document languages that refer to CSS stylesheets that are decoded from bytes
441+
must define an <dfn data-dfn-type=dfn data-noexport="" id=environment-encoding0>environment encoding<a class=self-link href=#environment-encoding0></a></dfn> for each such stylesheet,
442+
which is used as a fallback when other encoding hints are not available or can not be used.
443+
444+
<h4 class="heading settled heading" data-level=3.3.1 id=environment-encoding-at-import><span class=secno>3.3.1 </span><span class=content>
445+
<a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#at-ruledef-import title=@import>@import</a> rules</span><a class=self-link href=#environment-encoding-at-import></a></h4>
446+
447+
<p> For stylesheets referred to by an <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/css-cascade-3/#at-ruledef-import title=@import>@import</a> CSS rule <a data-biblio-type=normative data-link-type=biblio href=#css3cascade title=css3cascade>[CSS3CASCADE]</a>,
448+
the <a data-link-type=dfn href=#environment-encoding0 title="environment encoding">environment encoding</a> is the encoding of the referring stylesheet.
449+
450+
<p class=note> Note: this should be moved to <a data-biblio-type=informative data-link-type=biblio href=#css3cascade title=css3cascade>[CSS3CASCADE]</a>.
451+
452+
<h4 class="heading settled heading" data-level=3.3.2 id=environment-encoding-html><span class=secno>3.3.2 </span><span class=content>
453+
HTML</span><a class=self-link href=#environment-encoding-html></a></h4>
454+
455+
<p> For stylesheets referred to by an HTML <a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#link-type-stylesheet><code>&lt;link rel=stylesheet&gt;</code></a> element,
456+
the <a data-link-type=dfn href=#environment-encoding0 title="environment encoding">environment encoding</a> is the encoding of the referring document.
457+
458+
<p class=note> Note: this should be moved to the HTML spec.
459+
460+
<h4 class="heading settled heading" data-level=3.3.3 id=environment-encoding-xml><span class=secno>3.3.3 </span><span class=content>
461+
XML</span><a class=self-link href=#environment-encoding-xml></a></h4>
442462

463+
<p> For stylesheets referred to by an <a href=http://www.w3.org/TR/xml-stylesheet/#the-xml-stylesheet-processing-instruction><code>xml-stylesheet</code></a> processing instruction <a data-biblio-type=normative data-link-type=biblio href=#xmlstyle title=xmlstyle>[XMLSTYLE]</a>,
464+
the <a data-link-type=dfn href=#environment-encoding0 title="environment encoding">environment encoding</a> is determined as follows:
443465

444-
<h3 class="heading settled heading" data-level=3.3 id=input-preprocessing><span class=secno>3.3 </span><span class=content>
466+
<p> <ul>
467+
<li>
468+
<a data-link-type=dfn href=#get-an-encoding title="get an encoding">Get an encoding</a> for the value of the <code>charset</code> <a href=http://www.w3.org/TR/xml-stylesheet/#dt-pseudo-attribute>pseudo-attribute</a> on processing instruction, if any.
469+
If that does not return failure,
470+
use the return value as the environment encoding.
471+
472+
<li>
473+
Otherwise, use the encoding of the referring document.
474+
</ul>
475+
476+
<p class=note> Note: This should be moved to <a data-biblio-type=informative data-link-type=biblio href=#cssom title=cssom>[CSSOM]</a>.
477+
478+
479+
<h3 class="heading settled heading" data-level=3.4 id=input-preprocessing><span class=secno>3.4 </span><span class=content>
445480
Preprocessing the input stream</span><a class=self-link href=#input-preprocessing></a></h3>
446481

447482
<p> The input stream consists of the <a data-link-type=dfn href=#code-point title="code points">code points</a>
@@ -4750,11 +4785,11 @@ <h2 class="no-num no-ref heading settled heading" id=references><span class=cont
47504785

47514786
<h3 class="no-num no-ref heading settled heading" id=normative><span class=content>
47524787
Normative References</span><a class=self-link href=#normative></a></h3>
4753-
<div data-fill-with=normative-references><dl><dt id=css21 title=CSS21><a class=self-link href=#css21></a>[CSS21]<dd>Bert Bos; et al. <a href=http://www.w3.org/TR/2011/REC-CSS2-20110607>Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-CSS2-20110607>http://www.w3.org/TR/2011/REC-CSS2-20110607</a><dt id=css3cascade title=CSS3CASCADE><a class=self-link href=#css3cascade></a>[CSS3CASCADE]<dd>Håkon Wium Lie; Elika J. Etemad; Tab Atkins Jr.. <a href=http://www.w3.org/TR/2013/WD-css3-cascade-20130103/>CSS Cascading and Inheritance Level 3</a>. 3 January 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css3-cascade-20130103/>http://www.w3.org/TR/2013/WD-css3-cascade-20130103/</a><dt id=rfc2119 title=RFC2119><a class=self-link href=#rfc2119></a>[RFC2119]<dd>S. Bradner. <a href=http://www.ietf.org/rfc/rfc2119.txt>Key words for use in RFCs to Indicate Requirement Levels</a>. URL: <a href=http://www.ietf.org/rfc/rfc2119.txt>http://www.ietf.org/rfc/rfc2119.txt</a><dt id=select title=SELECT><a class=self-link href=#select></a>[SELECT]<dd>Tantek Çelik; et al. <a href=http://www.w3.org/TR/2011/REC-css3-selectors-20110929/>Selectors Level 3</a>. 29 September 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-css3-selectors-20110929/>http://www.w3.org/TR/2011/REC-css3-selectors-20110929/</a></dl></div>
4788+
<div data-fill-with=normative-references><dl><dt id=css21 title=CSS21><a class=self-link href=#css21></a>[CSS21]<dd>Bert Bos; et al. <a href=http://www.w3.org/TR/2011/REC-CSS2-20110607>Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-CSS2-20110607>http://www.w3.org/TR/2011/REC-CSS2-20110607</a><dt id=css3cascade title=CSS3CASCADE><a class=self-link href=#css3cascade></a>[CSS3CASCADE]<dd>Håkon Wium Lie; Elika J. Etemad; Tab Atkins Jr.. <a href=http://www.w3.org/TR/2013/WD-css3-cascade-20130103/>CSS Cascading and Inheritance Level 3</a>. 3 January 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css3-cascade-20130103/>http://www.w3.org/TR/2013/WD-css3-cascade-20130103/</a><dt id=rfc2119 title=RFC2119><a class=self-link href=#rfc2119></a>[RFC2119]<dd>S. Bradner. <a href=http://www.ietf.org/rfc/rfc2119.txt>Key words for use in RFCs to Indicate Requirement Levels</a>. URL: <a href=http://www.ietf.org/rfc/rfc2119.txt>http://www.ietf.org/rfc/rfc2119.txt</a><dt id=select title=SELECT><a class=self-link href=#select></a>[SELECT]<dd>Tantek Çelik; et al. <a href=http://www.w3.org/TR/2011/REC-css3-selectors-20110929/>Selectors Level 3</a>. 29 September 2011. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2011/REC-css3-selectors-20110929/>http://www.w3.org/TR/2011/REC-css3-selectors-20110929/</a><dt id=xmlstyle title=XMLSTYLE><a class=self-link href=#xmlstyle></a>[XMLSTYLE]<dd>James Clark. <a href=http://www.w3.org/1999/06/REC-xml-stylesheet-19990629>Associating Style Sheets with XML documents</a>. 29 June 1999. W3C Recommendation. URL: <a href=http://www.w3.org/1999/06/REC-xml-stylesheet-19990629>http://www.w3.org/1999/06/REC-xml-stylesheet-19990629</a></dl></div>
47544789

47554790
<h3 class="no-num no-ref heading settled heading" id=informative><span class=content>
47564791
Informative References</span><a class=self-link href=#informative></a></h3>
4757-
<div data-fill-with=informative-references><dl><dt id=css-variables title=CSS-VARIABLES><a class=self-link href=#css-variables></a>[CSS-VARIABLES]<dd>Tab Atkins Jr.. <a href=http://www.w3.org/TR/2013/WD-css-variables-1-20130620/>CSS Custom Properties for Cascading Variables Module Level 1</a>. 20 June 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css-variables-1-20130620/>http://www.w3.org/TR/2013/WD-css-variables-1-20130620/</a><dt id=css3-animations title=CSS3-ANIMATIONS><a class=self-link href=#css3-animations></a>[CSS3-ANIMATIONS]<dd>Dean Jackson; et al. <a href=http://www.w3.org/TR/2013/WD-css3-animations-20130219/>CSS Animations</a>. 19 February 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css3-animations-20130219/>http://www.w3.org/TR/2013/WD-css3-animations-20130219/</a><dt id=css3-conditional title=CSS3-CONDITIONAL><a class=self-link href=#css3-conditional></a>[CSS3-CONDITIONAL]<dd>L. David Baron. <a href=http://www.w3.org/TR/2013/CR-css3-conditional-20130404/>CSS Conditional Rules Module Level 3</a>. 4 April 2013. W3C Candidate Recommendation. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/CR-css3-conditional-20130404/>http://www.w3.org/TR/2013/CR-css3-conditional-20130404/</a><dt id=mediaq title=MEDIAQ><a class=self-link href=#mediaq></a>[MEDIAQ]<dd>Florian Rivoal. <a href=http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/>Media Queries</a>. 19 June 2012. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/>http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/</a></dl></div>
4792+
<div data-fill-with=informative-references><dl><dt id=css-variables title=CSS-VARIABLES><a class=self-link href=#css-variables></a>[CSS-VARIABLES]<dd>Tab Atkins Jr.. <a href=http://www.w3.org/TR/2013/WD-css-variables-1-20130620/>CSS Custom Properties for Cascading Variables Module Level 1</a>. 20 June 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css-variables-1-20130620/>http://www.w3.org/TR/2013/WD-css-variables-1-20130620/</a><dt id=css3-animations title=CSS3-ANIMATIONS><a class=self-link href=#css3-animations></a>[CSS3-ANIMATIONS]<dd>Dean Jackson; et al. <a href=http://www.w3.org/TR/2013/WD-css3-animations-20130219/>CSS Animations</a>. 19 February 2013. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/WD-css3-animations-20130219/>http://www.w3.org/TR/2013/WD-css3-animations-20130219/</a><dt id=css3-conditional title=CSS3-CONDITIONAL><a class=self-link href=#css3-conditional></a>[CSS3-CONDITIONAL]<dd>L. David Baron. <a href=http://www.w3.org/TR/2013/CR-css3-conditional-20130404/>CSS Conditional Rules Module Level 3</a>. 4 April 2013. W3C Candidate Recommendation. (Work in progress.) URL: <a href=http://www.w3.org/TR/2013/CR-css3-conditional-20130404/>http://www.w3.org/TR/2013/CR-css3-conditional-20130404/</a><dt id=cssom title=CSSOM><a class=self-link href=#cssom></a>[CSSOM]<dd>Anne van Kesteren. <a href=http://www.w3.org/TR/2011/WD-cssom-20110712/>CSSOM</a>. 12 July 2011. W3C Working Draft. (Work in progress.) URL: <a href=http://www.w3.org/TR/2011/WD-cssom-20110712/>http://www.w3.org/TR/2011/WD-cssom-20110712/</a><dt id=mediaq title=MEDIAQ><a class=self-link href=#mediaq></a>[MEDIAQ]<dd>Florian Rivoal. <a href=http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/>Media Queries</a>. 19 June 2012. W3C Recommendation. URL: <a href=http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/>http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/</a></dl></div>
47584793

47594794
<h2 class="no-num no-ref heading settled heading" id=index><span class=content>
47604795
Index</span><a class=self-link href=#index></a></h2>
@@ -4815,6 +4850,7 @@ <h2 class="no-num no-ref heading settled heading" id=index><span class=content>
48154850
<li>encoding, <a href=#encoding title="section 8.2">8.2</a>
48164851
<li>ending token, <a href=#ending-token title="section 5.4.7">5.4.7</a>
48174852
<li>end of the range, <a href=#unicode-range-end title="section 4">4</a>
4853+
<li>environment encoding, <a href=#environment-encoding0 title="section 3.3">3.3</a>
48184854
<li>EOF code point, <a href=#eof-code-point title="section 4.2">4.2</a>
48194855
<li>&lt;EOF-token&gt;, <a href=#typedef-eof-token title="section 5.2">5.2</a>
48204856
<li>escaping, <a href=#escaping0 title="section 2.1">2.1</a>
@@ -4894,13 +4930,7 @@ <h2 class="no-num no-ref heading settled heading" id=property-index><span class=
48944930
<div data-fill-with=property-index><p>No properties defined.</div>
48954931

48964932

4897-
<h2 class="no-num heading settled" id=issues-index><span class=content>Issues Index</span><a class=self-link href=#issues-index></a></h2><div style="counter-reset: issue"><p class=issue>
4898-
Anne says that steps 3/4 should be an input to this algorithm from the specs that define importing stylesheet,
4899-
to make the algorithm as a whole cleaner.
4900-
Perhaps abstract it into the concept of an "environment charset" or something?
4901-
4902-
4903-
<a href=#issue-ead8fa31></a><div class=issue>
4933+
<h2 class="no-num heading settled" id=issues-index><span class=content>Issues Index</span><a class=self-link href=#issues-index></a></h2><div style="counter-reset: issue"><div class=issue>
49044934
The following notes should probably be translated into normative text in the relevant specs,
49054935
hooking this spec’s terms:
49064936

css-syntax/Overview.src.html

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,7 @@ <h3 id="input-byte-stream">
304304
Note: This mimics HTML <code>&lt;meta></code> behavior.
305305

306306
<li>
307-
Otherwise, <a>get an encoding</a> for the value of the <code>charset</code> attribute on the <code>&lt;link></code> element or <code>&lt;?xml-stylesheet?></code> processing instruction that caused the style sheet to be included, if any.
308-
If that does not return failure,
309-
use the return value as the fallback encoding.
310-
311-
<li>
312-
Otherwise, if the referring style sheet or document has an encoding,
307+
Otherwise, if an <a>environment encoding</a> is provided by the referring document,
313308
use that as the fallback encoding.
314309

315310
<li>
@@ -321,10 +316,46 @@ <h3 id="input-byte-stream">
321316
Note: the <a>decode</a> algorithm lets the byte order mark (BOM) take precedence,
322317
hence the usage of the term "fallback" above.
323318

324-
<p class='issue'>
325-
Anne says that steps 3/4 should be an input to this algorithm from the specs that define importing stylesheet,
326-
to make the algorithm as a whole cleaner.
327-
Perhaps abstract it into the concept of an "environment charset" or something?
319+
<h3 id="environment-encoding">
320+
Environment encoding</h3>
321+
322+
Document languages that refer to CSS stylesheets that are decoded from bytes
323+
must define an <dfn>environment encoding</dfn> for each such stylesheet,
324+
which is used as a fallback when other encoding hints are not available or can not be used.
325+
326+
<h4 id="environment-encoding-at-import">
327+
''@import'' rules</h4>
328+
329+
For stylesheets referred to by an ''@import'' CSS rule [[!CSS3CASCADE]],
330+
the <a>environment encoding</a> is the encoding of the referring stylesheet.
331+
332+
Note: this should be moved to [[CSS3CASCADE]].
333+
334+
<h4 id="environment-encoding-html">
335+
HTML</h4>
336+
337+
For stylesheets referred to by an HTML <a href=http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#link-type-stylesheet><code>&lt;link rel=stylesheet></code></a> element,
338+
the <a>environment encoding</a> is the encoding of the referring document.
339+
340+
Note: this should be moved to the HTML spec.
341+
342+
<h4 id="environment-encoding-xml">
343+
XML</h4>
344+
345+
For stylesheets referred to by an <a href=http://www.w3.org/TR/xml-stylesheet/#the-xml-stylesheet-processing-instruction><code>xml-stylesheet</code></a> processing instruction [[!XMLSTYLE]],
346+
the <a>environment encoding</a> is determined as follows:
347+
348+
<ul>
349+
<li>
350+
<a>Get an encoding</a> for the value of the <code>charset</code> <a href=http://www.w3.org/TR/xml-stylesheet/#dt-pseudo-attribute>pseudo-attribute</a> on processing instruction, if any.
351+
If that does not return failure,
352+
use the return value as the environment encoding.
353+
354+
<li>
355+
Otherwise, use the encoding of the referring document.
356+
</ul>
357+
358+
Note: This should be moved to [[CSSOM]].
328359

329360

330361
<h3 id="input-preprocessing">

0 commit comments

Comments
 (0)