152 |
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
153 |
Representation</h2> |
Representation</h2> |
154 |
|
|
155 |
|
<p>Subsections of this section define algorithms |
156 |
|
to <a href="#algorithm-serialize-a-simple-selector">serialize a simple |
157 |
|
selector</a> or <a href="#algorithm-serialize-a-group-of-selectors">serialize |
158 |
|
a group of selectors</a>.</p> |
159 |
|
|
160 |
<div class="issue ed"> |
<div class="issue ed"> |
161 |
<p><a href="http://suika.fam.cx/gate/cvs/*checkout*/markup/html/whatpm/Whatpm/CSS/SelectorsSerializer.pm">See the reference implementation</a> |
<p><a href="http://suika.fam.cx/gate/cvs/*checkout*/markup/html/whatpm/Whatpm/CSS/SelectorsSerializer.pm">See |
162 |
for now.</p> |
also the reference implementation</a> for now.</p> |
163 |
</div> |
</div> |
164 |
|
|
165 |
<div class="note memo"> |
<div class="note memo"> |
294 |
<h3>Serializing Simple Selectors</h3> |
<h3>Serializing Simple Selectors</h3> |
295 |
|
|
296 |
<p>No <abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
<p>No <abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
297 |
representation is defined for an invalid simple selector selector.</p> |
representation is defined for an invalid <a href="#simple-selector">simple |
298 |
|
selector</a>.</p> |
299 |
|
|
300 |
<p>To |
<p>To |
301 |
<dfn id=algorithm-serialize-a-simple-selector title="serialize a simple selector">serialize |
<dfn id=algorithm-serialize-a-simple-selector title="serialize a simple selector">serialize |
302 |
a simple selector (<dfn><var id=var-ss>ss</var></dfn>)</dfn>, |
a simple selector (<dfn><var id=var-ss>ss</var></dfn>)</dfn>, |
303 |
the following algorithm <em class=rfc2119>MUST</em> be used:</p> |
the following algorithm <em class=rfc2119>MUST</em> be used:</p> |
304 |
|
<ol> |
305 |
|
<li>Let <dfn id=var-r><var>r</var></dfn> an empty string.</li> |
306 |
|
<li>Process <var>ss</var> as following: |
307 |
|
|
308 |
<dl class=switch> |
<dl class=switch> |
309 |
<dt>If <var>ss</var> is a type or universal selector</dt> |
<dt>If <var>ss</var> is a type or universal selector</dt> |
310 |
<dd> |
<dd> |
318 |
prefix)</dt> |
prefix)</dt> |
319 |
<dd>Append a <code class=char>U+007C</code> |
<dd>Append a <code class=char>U+007C</code> |
320 |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
321 |
character to <var>result</var>.</dd> |
character to <var>r</var>.</dd> |
322 |
<dt>If no namespace is specified (by namespace prefix <code>*</code>, |
<dt>If no namespace is specified (by namespace prefix <code>*</code>, |
323 |
or by omitting namespace prefix where no default namespace is |
or by omitting namespace prefix where no default namespace is |
324 |
specified)</dt> |
specified)</dt> |
326 |
<code class=charname>ASTERISK</code> (<code class=char>*</code>) |
<code class=charname>ASTERISK</code> (<code class=char>*</code>) |
327 |
character, followed by a <code class=char>U+007C</code> |
character, followed by a <code class=char>U+007C</code> |
328 |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
329 |
character, to <var>result</var>.</dd> |
character, to <var>r</var>.</dd> |
330 |
</dl> |
</dl> |
331 |
</li> |
</li> |
332 |
<li>If <var>ss</var> is a type selector, append the |
<li>If <var>ss</var> is a type selector, append the |
333 |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
334 |
local name to <var>result</var>.</li> |
local name to <var>r</var>.</li> |
335 |
<li>If <var>ss</var> is a universal selector, append |
<li>If <var>ss</var> is a universal selector, append |
336 |
a <code class=char>U+002A</code> <code class=charname>ASTERISK</code> |
a <code class=char>U+002A</code> <code class=charname>ASTERISK</code> |
337 |
(<code class=char>*</code>) character to <var>result</var>.</li> |
(<code class=char>*</code>) character to <var>r</var>.</li> |
338 |
</ol> |
</ol> |
339 |
</dd> |
</dd> |
340 |
<dt>If <var>ss</var> is an attribute selector</dt> |
<dt>If <var>ss</var> is an attribute selector</dt> |
342 |
<ol> |
<ol> |
343 |
<li>Append a <code class=char>U+005B</code> <code class=charname>LEFT |
<li>Append a <code class=char>U+005B</code> <code class=charname>LEFT |
344 |
SQUARE BRACKET</code> (<code class=char>[</code>) to |
SQUARE BRACKET</code> (<code class=char>[</code>) to |
345 |
<var>result</var>.</li> |
<var>r</var>.</li> |
346 |
<li> |
<li> |
347 |
Append a namespace prefix as following: |
Append a namespace prefix as following: |
348 |
<dl> |
<dl> |
353 |
<dt>If the null namespace is specified</dt> |
<dt>If the null namespace is specified</dt> |
354 |
<dd>Append a <code class=char>U+007C</code> |
<dd>Append a <code class=char>U+007C</code> |
355 |
<code class=charname>VERTICAL BAR</code> character to |
<code class=charname>VERTICAL BAR</code> character to |
356 |
<var>result</var>.</dd> |
<var>r</var>.</dd> |
357 |
<dt>If no namespace is specified</dt> |
<dt>If no namespace is specified</dt> |
358 |
<dd>Append a <code class=char>U+002A</code> |
<dd>Append a <code class=char>U+002A</code> |
359 |
<code class=charname>ASTERISK</code> (<code class=char>*</code>) |
<code class=charname>ASTERISK</code> (<code class=char>*</code>) |
360 |
character, followed by a <code class=char>U+007C</code> |
character, followed by a <code class=char>U+007C</code> |
361 |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
<code class=charname>VERTICAL BAR</code> (<code class=char>|</code>) |
362 |
character, to <var>result</var>.</dd> |
character, to <var>r</var>.</dd> |
363 |
</dl> |
</dl> |
364 |
</li> |
</li> |
365 |
<li>Append the |
<li>Append the |
366 |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
367 |
local name to <var>result</var>.</li> |
local name to <var>r</var>.</li> |
368 |
<li>If a value is specified in <var>ss</var>: |
<li>If a value is specified in <var>ss</var>: |
369 |
<ol> |
<ol> |
370 |
<li>Depending on the way to match, append <code>=</code>, |
<li>Depending on the way to match, append <code>=</code>, |
371 |
<code>~=</code>, <code>|=</code>, <code>^=</code>, |
<code>~=</code>, <code>|=</code>, <code>^=</code>, |
372 |
<code>$=</code>, or <code>*=</code> to <var>result</var>.</li> |
<code>$=</code>, or <code>*=</code> to <var>r</var>.</li> |
373 |
<li>Append the |
<li>Append the |
374 |
<a href="#algorithm-normalize-a-string" title="normalize a string">normalized</a> |
<a href="#algorithm-normalize-a-string" title="normalize a string">normalized</a> |
375 |
value to <var>result</var>.</li> |
value to <var>r</var>.</li> |
376 |
</ol> |
</ol> |
377 |
</li> |
</li> |
378 |
<li>Append a <code class=char>U+005D</code> <code class=charname>RIGHT |
<li>Append a <code class=char>U+005D</code> <code class=charname>RIGHT |
379 |
SQUARE BRACKET</code> (<code class=char>]</code>) to |
SQUARE BRACKET</code> (<code class=char>]</code>) to |
380 |
<var>result</var>.</li> |
<var>r</var>.</li> |
381 |
</ol> |
</ol> |
382 |
</dd> |
</dd> |
383 |
<dt>If <var>ss</var> is a class selector</dt> |
<dt>If <var>ss</var> is a class selector</dt> |
384 |
<dd>Append a <code class=char>U+002E</code> <code class=charname>FULL |
<dd>Append a <code class=char>U+002E</code> <code class=charname>FULL |
385 |
STOP</code> (<code class=char>.</code>) character, followed |
STOP</code> (<code class=char>.</code>) character, followed |
386 |
by <a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
by <a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
387 |
class name, <var>result</var>.</dd> |
class name, to <var>r</var>.</dd> |
388 |
<dt>If <var>ss</var> is an <abbr>ID</abbr> selector</dt> |
<dt>If <var>ss</var> is an <abbr>ID</abbr> selector</dt> |
389 |
<dd>Append a <code class=char>U+0023</code> <code class=charname>NUMBER |
<dd>Append a <code class=char>U+0023</code> <code class=charname>NUMBER |
390 |
SIGN</code> (<code class=char>#</code>) character, followed |
SIGN</code> (<code class=char>#</code>) character, followed |
391 |
by <a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
by <a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
392 |
<abbr>ID</abbr>, to <var>result</var>.</dd> |
<abbr>ID</abbr>, to <var>r</var>.</dd> |
393 |
<dt>If <var>ss</var> is a pseudo$B!>(Bclass selector</dt> |
<dt>If <var>ss</var> is a pseudo$B!>(Bclass selector</dt> |
394 |
<dd> |
<dd> |
395 |
<ol> |
<ol> |
396 |
<li>Append a <code class=char>U+003A</code> |
<li>Append a <code class=char>U+003A</code> |
397 |
<code class=charname>COLON</code> (<code class=char>:</code>) character |
<code class=charname>COLON</code> (<code class=char>:</code>) character |
398 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
399 |
<li>Append the |
<li>Append the |
400 |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
401 |
name of the pseudo$B!>(Bclass to <var>result</var>.</li> |
name of the pseudo$B!>(Bclass to <var>r</var>.</li> |
402 |
<li>Append any arguments as following: |
<li>Append any arguments as following: |
403 |
<dl class=switch> |
<dl class=switch> |
404 |
<dt>If the name of the pseudo$B!>(Bclass is <code>lang</code></dt> |
<dt>If the name of the pseudo$B!>(Bclass is <code>lang</code></dt> |
406 |
<ol> |
<ol> |
407 |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
408 |
PARENTHESIS</code> (<code class=char>(</code>) character |
PARENTHESIS</code> (<code class=char>(</code>) character |
409 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
410 |
<li>Append the |
<li>Append the |
411 |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
412 |
language tag (the argument) to <var>result</var>.</li> |
language tag (the argument) to <var>r</var>.</li> |
413 |
<li>Append a <code class=char>U+0029</code> |
<li>Append a <code class=char>U+0029</code> |
414 |
<code class=charname>RIGHT PARENTHESIS</code> |
<code class=charname>RIGHT PARENTHESIS</code> |
415 |
(<code class=char>)</code>) character |
(<code class=char>)</code>) character |
416 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
417 |
</ol> |
</ol> |
418 |
</dd> |
</dd> |
419 |
<dt>If the name of the pseudo$B!>(Bclass is |
<dt>If the name of the pseudo$B!>(Bclass is |
422 |
<ol> |
<ol> |
423 |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
424 |
PARENTHESIS</code> (<code class=char>(</code>) character |
PARENTHESIS</code> (<code class=char>(</code>) character |
425 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
426 |
<li>Append the |
<li>Append the |
427 |
<a href="#algorithm-normalize-a-string" title="normalize a string">normalized</a> |
<a href="#algorithm-normalize-a-string" title="normalize a string">normalized</a> |
428 |
string (the argument) to <var>result</var>.</li> |
string (the argument) to <var>r</var>.</li> |
429 |
<li>Append a <code class=char>U+0029</code> |
<li>Append a <code class=char>U+0029</code> |
430 |
<code class=charname>RIGHT PARENTHESIS</code> |
<code class=charname>RIGHT PARENTHESIS</code> |
431 |
(<code class=char>)</code>) character |
(<code class=char>)</code>) character |
432 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
433 |
</ol> |
</ol> |
434 |
</dd> |
</dd> |
435 |
<dt>If name of the pseudo$B!>(Bclass is either <code>nth-child</code>, |
<dt>If name of the pseudo$B!>(Bclass is either <code>nth-child</code>, |
439 |
<ol> |
<ol> |
440 |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
<li>Append a <code class=char>U+0028</code> <code class=charname>LEFT |
441 |
PARENTHESIS</code> (<code class=char>(</code>) character |
PARENTHESIS</code> (<code class=char>(</code>) character |
442 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
443 |
<li>Append <span class=ed>@@ normalized</span> |
<li>Append <span class=ed>@@ normalized</span> |
444 |
integer <var>a</var> to <var>result</var>. |
integer <var>a</var> to <var>r</var>. |
445 |
If the argument is a keyword <code>odd</code> or <code>even</code>, |
If the argument is a keyword <code>odd</code> or <code>even</code>, |
446 |
<var>a</var> is <code>2</code>. If <var>a</var> and |
<var>a</var> is <code>2</code>. If <var>a</var> and |
447 |
<code>n</code> is omitted, <var>a</var> is assumed as |
<code>n</code> is omitted, <var>a</var> is assumed as |
452 |
character).</li> |
character).</li> |
453 |
<li>Append a <code class=char>U+006E</code> |
<li>Append a <code class=char>U+006E</code> |
454 |
<code class=charname>LATIN SMALL LETTER N</code> |
<code class=charname>LATIN SMALL LETTER N</code> |
455 |
(<code class=char>n</code>) character to <var>result</var>.</li> |
(<code class=char>n</code>) character to <var>r</var>.</li> |
456 |
<li>Append <span class=ed>@@ normalized</span> |
<li>Append <span class=ed>@@ normalized</span> |
457 |
integer <var>b</var> to <var>result</var>. |
integer <var>b</var> to <var>r</var>. |
458 |
It <em class=rfc2119>MUST</em> be preceded by a sign, |
It <em class=rfc2119>MUST</em> be preceded by a sign, |
459 |
either <code class=char>U+002B</code> <code class=charname>PLUS |
either <code class=char>U+002B</code> <code class=charname>PLUS |
460 |
SIGN</code> (<code class=char>+</code>) or |
SIGN</code> (<code class=char>+</code>) or |
471 |
<li>Append a <code class=char>U+0029</code> |
<li>Append a <code class=char>U+0029</code> |
472 |
<code class=charname>RIGHT PARENTHESIS</code> |
<code class=charname>RIGHT PARENTHESIS</code> |
473 |
(<code class=char>)</code>) character |
(<code class=char>)</code>) character |
474 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
475 |
</ol> |
</ol> |
476 |
</dd> |
</dd> |
477 |
<dt>If the name of the pseudo$B!>(Bclass is <code>not</code></dt> |
<dt>If the name of the pseudo$B!>(Bclass is <code>not</code></dt> |
485 |
<code class=charname>LATIN SMALL LETTER T</code>, and |
<code class=charname>LATIN SMALL LETTER T</code>, and |
486 |
<code class=char>U+0028</code> <code class=charname>LEFT |
<code class=char>U+0028</code> <code class=charname>LEFT |
487 |
PARENTHESIS</code> (<code>:not(</code>), followed by a |
PARENTHESIS</code> (<code>:not(</code>), followed by a |
488 |
<a href="#newline">newline</a>, to <var>result</var>.</li> |
<a href="#newline">newline</a>, to <var>r</var>.</li> |
489 |
<li>Append four <code class=char>U+0020</code> |
<li>Append four <code class=char>U+0020</code> |
490 |
<code class=charname>SPACE</code> characters to |
<code class=charname>SPACE</code> characters to |
491 |
<var>result</var>.</li> |
<var>r</var>.</li> |
492 |
<li>Append four <code class=char>U+0020</code> |
<li>Append four <code class=char>U+0020</code> |
493 |
<code class=charname>SPACE</code> characters to |
<code class=charname>SPACE</code> characters to |
494 |
<var>result</var> again.</li> |
<var>r</var> again.</li> |
495 |
<li><a href="#algorithm-serialize-a-simple-selector">Serialize |
<li><a href="#algorithm-serialize-a-simple-selector">Serialize |
496 |
the simple selector specified as the argument to the |
the simple selector specified as the argument to the |
497 |
<code>not</code> pseudo$B!>(Bclass</a>.</li> |
<code>not</code> pseudo$B!>(Bclass</a>.</li> |
498 |
<li>Append a <a href="#newline">newline</a> to |
<li>Append a <a href="#newline">newline</a> to |
499 |
<var>result</var>.</li> |
<var>r</var>.</li> |
500 |
<li>Append four <code class=char>U+0020</code> |
<li>Append four <code class=char>U+0020</code> |
501 |
<code class=charname>SPACE</code> characters to |
<code class=charname>SPACE</code> characters to |
502 |
<var>result</var>.</li> |
<var>r</var>.</li> |
503 |
<li>Append a <code class=char>U+0029</code> |
<li>Append a <code class=char>U+0029</code> |
504 |
<code class=charname>RIGHT PARENTHESIS</code> |
<code class=charname>RIGHT PARENTHESIS</code> |
505 |
(<code class=char>)</code>) character |
(<code class=char>)</code>) character |
506 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
507 |
</ol> |
</ol> |
508 |
</dd> |
</dd> |
509 |
|
<dt>Otherwise</dt> |
510 |
|
<dd>The pseudo$B!>(Bclass is not supported by this version of |
511 |
|
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
512 |
|
and therefore no |
513 |
|
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
514 |
|
representation is defined for <var>ss</var>. Stop the algorithm.</dd> |
515 |
</dl> |
</dl> |
516 |
</li> |
</li> |
517 |
</ol> |
</ol> |
521 |
<ol> |
<ol> |
522 |
<li>Append two <code class=char>U+003A</code> |
<li>Append two <code class=char>U+003A</code> |
523 |
<code class=charname>COLON</code> characters (<code>::</code>) |
<code class=charname>COLON</code> characters (<code>::</code>) |
524 |
to <var>result</var>.</li> |
to <var>r</var>.</li> |
525 |
<li>Append the |
<li>Append the |
526 |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
<a href="#algorithm-normalize-an-ident" title="normalize an IDENT">normalized</a> |
527 |
name of the pseudo$B!>(Belement to <var>result</var>.</li> |
name of the pseudo$B!>(Belement to <var>r</var>.</li> |
528 |
<!-- For future version: append "(", arguments, ")", if any. --> |
<li>If the pseudo$B!>(Belement has any arguments: |
529 |
|
The pseudo$B!>(Belement is not supported by this version of |
530 |
|
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
531 |
|
and therefore no |
532 |
|
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
533 |
|
representation is defined for <var>ss</var>. Stop the algorithm. |
534 |
|
</li> |
535 |
</ol> |
</ol> |
536 |
</dd> |
</dd> |
537 |
</dl> |
</dl> |
538 |
|
</li> |
539 |
|
<li>Then, <var>r</var> is the |
540 |
|
<abbr title="Selectors Serialization Format for Testing">SSFT</abbr> |
541 |
|
representation of <var>ss</var>.</li> |
542 |
|
</ol> |
543 |
|
|
544 |
</div> |
</div> |
545 |
|
|
565 |
<li>Append four <code class=char>U+0020</code> |
<li>Append four <code class=char>U+0020</code> |
566 |
<code class=charname>SPACE</code> characters to <var>result</var>.</li> |
<code class=charname>SPACE</code> characters to <var>result</var>.</li> |
567 |
<li>Process each sequence of simple selectors or |
<li>Process each sequence of simple selectors or |
568 |
combinator in <var>selector</var> by following algorithm: |
combinator in <var>selector</var> as following: |
569 |
<dl class=switch> |
<dl class=switch> |
570 |
<dt>If it is a sequence of simle selector |
<dt>If it is a sequence of simle selector |
571 |
(<dfn id=var-sss><var>sss</var></dfn>)</dt> |
(<dfn id=var-sss><var>sss</var></dfn>)</dt> |
582 |
<ol> |
<ol> |
583 |
<li>Append two <code class=char>U+0020</code> |
<li>Append two <code class=char>U+0020</code> |
584 |
<code class=charname>SPACE</code> characters to <var>result</var>.</li> |
<code class=charname>SPACE</code> characters to <var>result</var>.</li> |
585 |
<li> |
<li>Process <var>c</var> as following: |
586 |
|
|
587 |
<dl class=switch> |
<dl class=switch> |
588 |
<dt>If <var>c</var> is descendant combinator (white space)</dt> |
<dt>If <var>c</var> is descendant combinator (white space)</dt> |
589 |
<dd>Append a <code class=char>U+0020</code> |
<dd>Append a <code class=char>U+0020</code> |