Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/thlorenz/prune-html
- Owner: thlorenz
- License: mit
- Created: 2013-12-16T21:07:36.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-26T14:53:05.000Z (almost 11 years ago)
- Last Synced: 2024-10-18T00:33:05.856Z (3 months ago)
- Language: JavaScript
- Homepage: https://github.com/thlorenz/prune-html
- Size: 213 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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>
|
Stringif 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.Returns:
the pruned html
Type
string*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT
[cheerio attributes]: https://github.com/MatthewMueller/cheerio#attributes