Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zaro/node-htmlstrip-native
Nodejs module for stripping html tags
https://github.com/zaro/node-htmlstrip-native
Last synced: 3 months ago
JSON representation
Nodejs module for stripping html tags
- Host: GitHub
- URL: https://github.com/zaro/node-htmlstrip-native
- Owner: zaro
- License: other
- Created: 2013-06-19T11:06:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-04T08:25:42.000Z (over 3 years ago)
- Last Synced: 2024-10-05T13:45:41.975Z (4 months ago)
- Language: C++
- Homepage:
- Size: 138 KB
- Stars: 21
- Watchers: 3
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#Simple HTML tags stripping library
## Install
via npm:
npm install htmlstrip-native
from source [![Build Status](https://travis-ci.org/zaro/node-htmlstrip-native.svg?branch=master)](https://travis-ci.org/zaro/node-htmlstrip-native) :
git clone git://github.com/zaro/node-htmlstrip-native.git
cd node-htmlstrip-native
npm install## Use
Example:
```js
var html_strip = require('htmlstrip-native');var html = 'b {color: red;}' +
' Yey, No more, tags' +
'document.write("Hello from Javascript")';
var options = {
include_script : false,
include_style : false,
compact_whitespace : true,
include_attributes : { 'alt': true }
};// Strip tags and decode HTML entities
var text = html_strip.html_strip(html,options);console.log(text)
// Decode HTML entities only
var no_entities = html_strip.html_entities_decode('Hello ⌣')
```The html_strip function expects either a string as first argument or a 'utf-16le',
encoded Buffer. The optional second argument can hold the following options:```js
{
include_script : true, // include the content of tags
include_style : true, // include the content of <style> tags
compact_whitespace : false // compact consecutive '\s' whitespace into single char
include_attributes : { // include attribute values in the output
'*':true , // special value, means : Include ALL attributes
'alt': true , // include attributes named 'alt'
}
}
```## Speed
Same thing can be achieved really simply without native modules with htmlparser2 for example.
This module is ~30 times faster than using htmlparser2.