GithubHelp home page GithubHelp logo

arthurfranca / node-htmlstrip-native Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zaro/node-htmlstrip-native

0.0 2.0 0.0 135 KB

Nodejs module for stripping html tags

License: Other

C++ 93.55% Python 0.12% JavaScript 6.26% Shell 0.07%

node-htmlstrip-native's Introduction

#Simple HTML tags stripping library

Install

via npm:

npm install htmlstrip-native

from source Build Status :

git clone git://github.com/zaro/node-htmlstrip-native.git
cd node-htmlstrip-native
npm install

Use

Example:

var html_strip = require('htmlstrip-native');

var html = '<style>b {color: red;}</style>' +
					 ' Yey, <b> No more, tags</b>' +
					 '<script>document.write("Hello from Javascript")</script>';
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 &smile;')

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:

{
  include_script : true, // include the content of <script> 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.

node-htmlstrip-native's People

Contributors

cauldrath avatar dvic avatar zaro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.