Skip to content

[css-pseudo-4] Fine-tuning ::first-letter punctuation pattern matching #5830

Closed
@fantasai

Description

@fantasai

In #5154 we updated the spec to include "intervening" white space. Certainly for spaces before the first letter this is correct, but the example of “A "b" will have A " selected” in @csnardi’s #2164 (comment) shows a real problem with this approach: since we reach out to following punctuation, allowing intervening white space after the first letter means we'll jump a word space and scoop up opening punctuation on the other side. :( I think we definitely need to make this smarter.

A few rules we could adopt that could help:

  • Break on normal word spaces and nbsp, at least on the following side of the first letter. If people want to scoop up subsequent punctuation after a space, they'll have to use typographically correct space codepoints such as thinsp.
  • Exclude opening punctuation following the first letter. In writing systems without a word space, we shouldn't be picking up the opening parens after the first "letter"! Po/Pi/Pf are ambiguous, but Ps is not.
  • If there's an element boundary after the first letter, require that the UA close ::first-letter before that boundary, excluding the content after that element boundary, rather than allowing them to create ::first-letter after (excluding the first letter itself!) or both before and after the element boundary as we do currently.

I think we also need to do some more thinking about following Po/Pi/Pf/Pd. E.g. CSS2 and Selectors 3 excluded Pd entirely but we generalized to all of P*. And we actually do need to include Pd before the letter because dashes are frequently used as an opening quotation mark, but is slurping them up into the ::first-letter after the letter correct?

CC @dauwhe @r12a @faceless2 @johannesodland

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions