styleless-innertext
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

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
});

Readme

Keywords

Package Sidebar

Install

npm i styleless-innertext

Weekly Downloads

4

Version

1.1.5

License

ISC

Unpacked Size

14.1 kB

Total Files

6

Last publish

Collaborators

  • saschanaz