Re: [csswg-drafts] [css-gcpm-3] string-set with counter(page), when is value resolved? (#4740)

I've been trying to figure out why anyone would use `string-set: f, counter(page))` and `content: string(f)` instead of just `content: counter(page)`, as it seems to have no benefit.

The answer is that it lets you do this
```css
@page {
  @top-left {
    content: string(page-number, first-except);
  }
}
section {
    string-set: page-number counter(page);
}
```
Prince's implementation uses this approach with `first-except` to let you _not display_ the page number on the first page of the section - the page where the string was set.

I still think this approach doesn't match what's currently specified. But it explains why it's considered useful, and it's an effect that's difficult to reproduce without this behaviour (you need the `:nth()` page selector). It's also clear from the differing results above that a) the behaviour needs defining one way or another, and b) doing so is going to cause either prince, or everyone else, to change the behaviour.

---

Can we define the behaviour of Prince in a general way so that it's applicable for all counters and doesn't require magic for `page`? Yes I think we can, with something like the following text added to the definition of `string-set`:

> When the value of a string includes a `counter()` or `counters()` function, it is treated as a _reference_ to that counter, not as a copy of the current counter value.

and the following added to the definition of `string()`:

> The second argument to the `string()` function is used to determine not only which _value_ of the string is used, but also - if that chosen value of the string contains a counter reference - which _value_ of the counter is displayed. The _entry value_ for a counter will include any assignments made in the page margin.

With this revised definition, the output from the example above would be page1=1111, page2=222, page3=3333.

I'll test this out next week to see if it works in practice. It would still be really, really useful to see what Antenna House's renderer does with the above example:

@tabatkins I recall you downloaded AH renderer for another issue. Any chance you could try https://github.com/w3c/csswg-drafts/issues/4740#issuecomment-592085773 and update this issue with the results?

-- 
GitHub Notification of comment by faceless2
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4740#issuecomment-633028693 using your GitHub account

Received on Saturday, 23 May 2020 11:10:25 UTC