[Discussion] textContent vs. innerText
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13k
- Forks
- 1.4k
- Avg merge
- 15h 36m
- Merged PRs (30d)
- 3
Description
In #1764 we began a discussion as to whether Prism.highlightElement should use textContent or innerText to get the text of the element to highlight.
Summary:
- If the element to be highlighted doesn't contain any tags,
innerTextandtextContentwill return the same text. innerTextonly returns the human-readable text of the element which makes it more intuitive.textContentignores the meaning of all tags. This causes linebreaks that are implemented via<br>or a wrapper withdisplay: blockto be ignored.- The result of
innerTextdepends on whether the element is visible. (If it's not visible it will return the same astextContent.) textContentis generally faster.
innerTexttakes the current style of the element (plus children) into account (which might require the layout to be recomputed).
Additional concerns:
- Changing to
innerTextmight break the code of some people. - There are behavioral differences for
innerTextin some older browsers. - We have to change the implementation of Keep markup, Line numbers, and Normalize whitespace when using
innerText.
Not concerns:
- Both
innerTextandtextContenthave to good cross-browser compatibility with some older version of Firefox not supportinginnerTextand some older versions of IE not supportingtextContent. - We don't have to change the implementation of Unescaped markup when using
innerText.
/cc @SetTrend @mAAdhaTTah @Golmote @LeaVerou
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Prism.highlightElement entry point and review the Keep markup, Line numbers, and Normalize whitespace plugins named in the discussion. Compare the current behavior of textContent and innerText, including visibility and browser differences. Done requires an agreed choice and coordinated behavior across the affected implementation and plugins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100