[CSS21][css3-content] quotes nesting level

Hi,

Both section 12.3.2 of CSS 2.1 and section 4.1 of Generated Content 3 
use the same text to describe the quotes nesting level for the `quotes` 
property and the `open-quote` and `close-quote` values of the `content` 
property:

"""
‘Open-quote’ refers to the first of a pair of quotes, ‘close-quote’ 
refers to the second. Which pair of quotes is used depends on the 
nesting level of quotes: the number of occurrences of ‘open-quote’ in 
all generated text before the current occurrence, minus the number of 
occurrences of ‘close-quote’. If the depth is 0, the first pair is used, 
if the depth is 1, the second pair is used, etc. If the depth is greater 
than the number of pairs, the last pair is repeated.
"""

For the quotes to be balanced and match the examples, the nesting level 
should be more accurately described as:

the number of occurrences of ‘open-quote’ in all generated text before 
the current occurrence *excluding the current occurrence*, minus the 
number of occurrences of ‘close-quote’ before the current occurrence 
*including the current occurrence*.

Of course this sentence is much too heavy but I couldn’t find a better 
way to explain it in prose.

For example, if a sequence of quotes is:

     open   open close   open  open close  close   close
    (spacing added for clarity)

Then we want the nesting levels to be, respectively:

     0      1    1      1     2    2     1      0
     =0-0   =1-0 =2-1   =2-1  =3-1 =4-2  =4-3   =4-4

The algorithm to implement this cloud be:

     nesting_level = 0
     for each occurrence of *-quote in content:
         if it is close-quote or no-close-quote:
             decrement nesting_level (with a minimum at 0)
         if it is open-close or close-quote:
             insert the quote at nesting_level
         if it is open-quote or no-open-quote:
             increment nesting_level

The order in which each of the three operations must be done is 
important but not intuitive. The current prose did not help at all to 
get at it.

Regards,
-- 
Simon Sapin

Received on Monday, 5 December 2011 16:51:55 UTC