-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spec innerText #5
Comments
When Aryeh wrote a spec, nobody was interested in implementing it; what makes you think this attempt will go any better? |
@Ms2ger Yeah one of these. It might not get any better. I usually don't think ;) I'm opening the issues on what is needing for the Web Compatibility. We will figure out if/how to spec it if/when implemented. Currently it is mostly used as a replacement for textContent in all the bugs we can see. |
I wrote some things in a duped bug: Usage is very high: As implemented in Blink these attributes depend on layout, but it's not obvious that this is required for web compat, maybe a "semantic textContent" that does special things for a small number of elements like However someone attempts to specify it, I'd be happy to investigate the difference between that and what's implemented in Blink. |
Next up on the ladder of crazy would be depending on the computed style, which is still better than depending on the layout structure itself, IMHO. |
fyi Anne said "To do this right, you would first have to standardize selection." http://discourse.wicg.io/t/standardizing-innertext/799/2 |
@annevk, what does that mean? Not http://w3c.github.io/selection-api/ I take it? |
Yes, that. |
Oh, and that's undefined in the spec with a link to https://www.w3.org/Bugs/Public/show_bug.cgi?id=10583 So in other words, what we need is a common algorithm that takes a range (containing the context object for I guess setting |
Setting operates on the DOM directly, with no regards for layout? Or is setting "magic" too? |
For some odd reason, The |
Well if you just set |
It's weird, in the normal case the text is converted to Text nodes and |
I've drafted a proposal for a robust, CSS-based approach to the element -> text conversion both |
Searching innerText in Chromium
String Element::outerText()
{
// Getting outerText is the same as getting innerText, only
// setting is different. You would think this should get the plain
// text for the outer range, but this is wrong, <br> for instance
// would return different values for inner and outer text by such
// a rule, but it doesn't in WinIE, and we want to match that.
return innerText();
}
String Element::innerText()
{
// We need to update layout, since plainText uses line boxes in the layout tree.
document().updateLayoutIgnorePendingStylesheets();
if (!layoutObject())
return textContent(true);
return plainText(EphemeralRange::rangeOfContents(*this), TextIteratorForInnerText);
} |
Which is basically how it was defined in WebKit source code. It didn't change. |
We have decided to implement innerText in Gecko, because people keep using it. So we want a spec. |
@rocallahan I've started https://github.com/stuartpb/css-plaintext, based on what I've written in http://discourse.wicg.io/t/css-plain-text-conversion/976. It defines a number of new CSS properties, but UAs can choose to treat those properties as having their default values for a "simple" initial implementation. |
Thanks. I don't want to try to describe innerText in terms of CSS, because we won't want to implement it that way. I prefer an algorithm like Aryeh's or Kangax's. |
Well, if you look at implementations like Chromium's (as @karlcow posted above), it ends up having to go through the layout engine anyway, since any reliable, useful |
Yes. The algorithm will need to examine the computed style values of DOM nodes. |
But we won't define any new CSS properties. |
Well, the CSS properties css-plaintext proposes, which only impact plaintext conversion of elements, are there to ease the rational differences of opinion user agents currently have between each other regarding the processing of said computed styles, which page authors should be able to control (per the Extensible Web Manifesto). |
EWM isn't an issue here. Web developers can easily polyfill their own version of innerText using existing standard APIs. In fact, since there is no one true way to convert HTML to plain text, innerText should not be in the Web platform at all. But since sites rely on it, we can't get rid of it, and we need to converge on a good, reasonably simple spec for this misfeature. |
And we definitely don't want to extend innerText with additional features such as control over plaintext conversion. If you don't like what innerText does, roll your own from scratch. Many libraries already have. |
I have created a proposed spec plus testsuite here: https://github.com/rocallahan/innerText-spec |
Now implemented in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=264412#c125 |
@rocallahan, I see that some tests in http://rocallahan.github.io/innerText-spec/getter-tests.html fail in Blink, did you reverse engineer Blink and would you happen to already know the main changes that would be needed to match your spec? It would be interesting to see how much work that would be, and if it seems risky or not. |
I did not reverse engineer Blink's implementation. I was aiming for something that was simple and logical while having a high degree of Blink compatibility as observed in my tests. Looking at the Blink failures, I think most of them are pretty clearly bugs:
The main differences that are not clearly bugs are handling of Given the massive failure of interoperability between Blink and Edge in most of the edge cases, plus having looked at how |
So it looks like in Blink, innerText is implemented using a code path that's shared (with behavior flags) with a bunch of other contexts, including Range and Selection. @hayatoito, @yosin-chromium, I think this would fall under the editing code in Blink, are either of you interested in this? Do you know if yoichio@ has a Github account? |
I'm pretty sure that @yosin-chromium is interested in this. I'm also interested in how innerText would interact with Shadow DOM. We discussed this topic internally, however, since innerText doesn't have a spec, we couldn't define the behavior formally. |
Handling of CSS text-transform is also different among browsers:
BTW, should we include text contents from :before/:after CSS pseudo element? Sample: https://jsfiddle.net/p5f0t0qp/3/ |
My intent is that once
Currently I'm proposing that
The
Existing implementations don't do this, so I made the spec not do this. |
Yeah, that sounds reasonable as the first step. @yosin-chromium, |
We're measuring usage of shadow DOM with innerText, It seems there are no usage so far. I think we can omit shadow DOM support from Blink, |
I think it needs clarification:
Is my understanding correct? |
Correct. Thanks for clarification. |
In http://crbug.com/536137, one user wants to have innerText for response of XMLHttpRequest(), |
Oh, I just found it used in our |
To avoid having to respecify and reimplement CSS features I've made the innerText spec depend heavily on having a CSS layout for the DOM nodes (as it's implemented in Webkit, Blink and now Gecko). I don't think it makes sense to change direction on that. So to apply innerText to the results of an XMLHttpRequest you'll have to put the nodes in a hidden <iframe> or something like that. I don't think that's a major problem. |
For those that haven't seen yet, here's innerText compat table — http://kangax.github.io/jstests/innerText/ /cc @yosin-chromium I'll try to add few of Robert's tests as well. |
FWIW I tried to incorporate everything in those tests into my tests. |
I think we can close this now, @rocallahan has written a spec over at http://rocallahan.github.io/innerText-spec/. Any issues on that can be raised against https://github.com/rocallahan/innerText-spec/issues. 🎈 🍰 |
Firefox 46 passes all tests, landed in Firefox 45 https://bugzilla.mozilla.org/show_bug.cgi?id=264412 |
FTR whatwg/html#465 |
Excellent \o/ Thanks 🚀 |
Firefox: Add support for element.outerText |
The innerText is used in a number of Web sites creating interop issues.
see https://bugzilla.mozilla.org/show_bug.cgi?id=264412
The text was updated successfully, but these errors were encountered: