A library to imitate WHATWG HTMLElement.innerText specification
npm install styleless-innertextA library to imitate WHATWG HTMLElement.innerText specification. It ignores CSS styles by default, unless getComputedStyle function is explicitly given.
``js
const innerText = require("styleless-innertext");
const { JSDOM } = require("jsdom");
const html =
| Name | Age |
|---|---|
| Abe Nana | 17 |
;// Gives "Name\tAge\nAbe Nana\t17"
innerText(JSDOM.fragment(html).firstChild);
// CSS-agnostic way, gives "inline text"
const csshtml =
;
const scope = new JSDOM(csshtml).window;
innerText(scope.document.body, {
getComputedStyle: scope.getComputedStyle
});
``