4 ms·
Not even counting the numerous cases of white spaces[1], combining characters, non-breaking space, figure space, soft hyphens or zero-width joiners. This sounds
by mxfh 12y ago
Not even counting the numerous cases of white spaces[1], combining characters, non-breaking space, figure space, soft hyphens or zero-width joiners.
This sounds difficult enough in latin script, almost impossible to capture all cases in non LTR, non-latin grapheme based texts.
[1] http://en.wikipedia.org/wiki/Whitespace_character http://en.wikipedia.org/wiki/Whitespace_character
- kangax 12y agoBut browsers already take care of this. They collapse all the spaces in markup for non-pre-formatted blocks; they render block/inline elements accordingly; insert newlines where needed, etc. And then, once you select some text from the page — there's your "plain text" representation. We probably can't avoid differences among browsers (simply due to the vast nature of HTML — form controls, media content, generated content, new elements like <template>, non-standard extensions, etc.) but in context of a single browser, the logic already exists beneath. It's just not exposed conveniently.