broccoli-dom-filter

1.0.0 • Public • Published

Broccoli Dom Filter

Latest npm release TravisCI Build Status GitHub Actions CI

Broccoli plugin for manipulating HTML with jsdom.

Usage

Add an Element in app/index.html:

const BroccoliDomFilter = require('broccoli-dom-filter');
 
const filter = new BroccoliDomFilter('app', {
  files: ['index.html'],
  processors: [(jsdom => {
    const document = jsdom.window.document;
    const head = document.querySelector('head');
    const insertBefore = head.querySelector('title');
    const meta = document.createElement('meta');
 
    meta.setAttribute('name', 'test-name');
    meta.setAttribute('content', 'test-content');
 
    head.insertBefore(meta, insertBefore);
 
    return jsdom;
  })],
});

Documentation

new BroccoliDomFilter(inputNodes, options)

BroccoliDomFilter is a subclass of BroccoliPersistentFilter which has additional options available in the constructor. Please see BroccoliPersistentFilter Options for documentation.

  • inputNodes: An array of node objects that this plugin will read from. Nodes are usually other plugin instances; they were formerly known as "trees".
  • options
    • files: The list of files to process the list of patterns against. This is an array of strings.
    • processors: An array of callbacks that will process jsdom and return jsdom.
    • processorOptions: A context that can will be passed as the second argument to a processor.

function processor(jsdom, processorOptions = {})

Processors allow you to modify the document currently being processed by jsdom. A processor MUST take the jsdom argument and MUST return the jsdom argument. If you created an instance of BroccoliDomFilter with processorOptions, that is provided to your processor as the second argument, otherwise it will default to {}.

Tests

npm install
npm test

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i broccoli-dom-filter

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.01 kB

Total Files

6

Last publish

Collaborators

  • atsjj