Skip to content

Calculates standard innerText value for unrendered elements

License

Notifications You must be signed in to change notification settings

saschanaz/styleless-innertext

Repository files navigation

styleless-innertext

A library to imitate WHATWG HTMLElement.innerText specification. It ignores CSS styles by default, unless getComputedStyle function is explicitly given.

const innerText = require("styleless-innertext");
const { JSDOM } = require("jsdom");

const html = `<table>
  <tr><th>Name</th><th>Age</th></tr>
  <tr><td>Abe Nana</td><td>17</td></tr>
</table>`;

// Gives "Name\tAge\nAbe Nana\t17"
innerText(JSDOM.fragment(html).firstChild);

// CSS-agnostic way, gives "inline text"
const csshtml = `<style>.inline { display: inline }</style>
<div class="inline">inline</div> <div class="inline">text</div>`;
const scope = new JSDOM(csshtml).window;
innerText(scope.document.body, {
  getComputedStyle: scope.getComputedStyle
});

About

Calculates standard innerText value for unrendered elements

Resources

License

Stars

Watchers

Forks

Packages

No packages published