Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thlorenz/prune-html

Given an html string it removes elements matching CSS selector(s) and returns the pruned html string.
https://github.com/thlorenz/prune-html

Last synced: 2 months ago
JSON representation

Given an html string it removes elements matching CSS selector(s) and returns the pruned html string.

Awesome Lists containing this project

README

        

# prune-html [![build status](https://secure.travis-ci.org/thlorenz/prune-html.png)](http://travis-ci.org/thlorenz/prune-html)

Given an html string it removes elements matching CSS selector(s) and returns the pruned html string.

```js
var pruneHtml = require('prune-html');

var html = [
'

'
, '

Global

'
, ' '
, '

Hello

'
, ' '
, ' '
, '
'
, '
'
, '
'
, '

Methods

'
, ' '
, '
'
].join('\n')

console.log(pruneHtml([ 'h1', '.details', 'h3' ], html));
/* =>



Hello







*/
```

You can further refine the element filtering using [cheerio attributes][].

```js
var pruneHtml = require('prune-html');

var html = [
'

'
, '
'
, '
'
].join('\n');

function filterPruneData() {
return this.data('prune') !== undefined;
}

console.log(pruneHtml([ '*' ], html, filterPruneData));
/* =>



*/
```

## Installation

npm install prune-html

## API









pruneHtml(selectors, html, filter) → {string}





Prunes all elements matching the selectors from the given html and returns result.



Parameters:

Name
Type
Argument
Description

selectors

Array.<String>
|
String

if one of these CSS selector(s) matches, the element is pruned

html

string

unpruned html

filter

function

<optional>

function which can be used to filter elements further. Inside the function, this refers to the current element.


Source:



Returns:


the pruned html





Type


string



*generated with [docme](https://github.com/thlorenz/docme)*

## License

MIT

[cheerio attributes]: https://github.com/MatthewMueller/cheerio#attributes