[csswg-drafts] [css-text] `&ncsp;` - Non-Collapsible Space (#10821)

dgp1130 has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-text] `&ncsp;` - Non-Collapsible Space ==
HTML whitespace collapsing behavior makes it very difficult to directly manage individual spaces rendered in an HTML document. Whitespace collapsing has a few problems today:
1. Content management systems cannot just blindly pass text written by a non-developer through to an HTML rendering context. If a user types `Hello,       World` in a CMS system, it will be rendered as `Hello, World` in HTML. The CMS can't really do anything about this to get the document to render as intended by the author without forcing all strings to use `white-space: pre;`.
1. `white-space: pre;` applies to the whole element, but the user might want two spaces in a particular place within that element. For example, maybe I'm one of those people who insists on two spaces at the end of every sentence.
1. ` ` sounds like an easy fix for "Just add a space here", but forces non-breaking and a forced-width behavior the user may not want (when line wrapped, ` ` always takes up one space of width, even when that's not needed). See the line wrapping behavior of [this demo](https://stackblitz.com/edit/vitejs-vite-datbwc?file=index.html&terminal=dev) as the viewport shrinks.
1. ` ` is the unnamed entity for a single space, which sounds like it would be a good alternative given that I really want the behavior for a simple space. However, ` ` is also subject to whitespace collapsing so it can't really solve this kind of problem. This feels especially weird since whitespace collapsing exists as an affordance to developers who want to format their HTML source code differently from the rendered output, but any developer who writes ` ` clearly wants that space to be rendered as-is. Collapsing those spaces goes directly against developer expectations.
 
I propose a new `&ncsp;` entity which is treated identically to a regular space, however is not subject to whitespace collapsing. You could write `Hello,&ncsp;&ncsp;&ncsp;&ncsp;&ncsp;World` and actually get multiple adjacent spaces like `Hello,     World`. This would address the above challenges because:
1. Content management systems can output `&ncsp;` where white space is significant.
2. Developers could use `&ncsp;` without having to opt-in an entire element into the rules of `white-space: pre;`.
3. `&ncsp;` could serve as a drop-in replacement for existing usages of ` ` but present better line wrapping behavior.
4. `&ncsp;` would work in the way I wish ` ` worked and behave in a more predictable fashion.

I'm not 100% which standards body is the right one to own this particular issue, however I filed it here because whitespace collapsing seems to be a part of the [`css-text` standard](https://drafts.csswg.org/css-text/). In theory, `&ncsp;` is just an alias for a standard space, one which just gets ignored by the whitespace collapsing algorithm. However, as I understand it based on the current layering of browsers, the HTML parser would resolve `&ncsp;` into a regular space character, and it would then be impossible for the CSS to disambiguate spaces which originated from `&ncsp;` entities. Therefore I suspect this would actually require a brand new Unicode character. If one were added for this purpose, then the existing `css-text` standard likely wouldn't need to be changed at all. However, it feels weird to add one solely to solve an HTML issue like this and I'm not sure that's feasible. What exactly would a non-collapsible space do in a non-HTML context? An alternative approach might be for the HTML parser to convert `&ncsp;` to a different, user-space Unicode character known by the `white-space` spec which gets rendered as a standard space but is otherwise ignored for collapsing. I'm not sure that's a great architectural idea, but its the one solution which comes to mind here.

Feel free to move this issue to whichever standards body makes the most sense to evaluate it.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10821 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 2 September 2024 21:37:12 UTC