Socket
Socket
Sign inDemoInstall

clean-html

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-html - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

18

index.js

@@ -1,2 +0,5 @@

var options = {
var options = {};
function setup(opt) {
options = {
'attr-to-remove': [

@@ -37,3 +40,2 @@ 'align',

function setup(opt) {
if (!opt) {

@@ -45,8 +47,8 @@ return;

options['block-tags'] = opt['block-tags'] || options['block-tags'];
options['break-after-br'] = opt['break-after-br'] === false ? false : options['break-after-br'];
options['close-empty-tags'] = opt['close-empty-tags'] || options['close-empty-tags'];
options['break-after-br'] = opt['break-after-br'] === false ? false : true;
options['close-empty-tags'] = opt['close-empty-tags'] === true ? true : false;
options['empty-tags'] = opt['empty-tags'] || options['empty-tags'];
options['indent'] = opt['indent'] || options['indent'];
options['pretty'] = opt['pretty'] === false ? false : options['pretty'];
options['remove-comments'] = opt['remove-comments'] || options['remove-comments'];
options['pretty'] = opt['pretty'] === false ? false : true;
options['remove-comments'] = opt['remove-comments'] === true ? true : false;
options['tags-to-remove'] = opt['tags-to-remove'] || options['tags-to-remove'];

@@ -153,6 +155,2 @@

function indent(html) {
if (!options['indent']) {
return;
}
var indentLevel = 0;

@@ -159,0 +157,0 @@

{
"name": "clean-html",
"version": "1.1.0",
"version": "1.1.1",
"description": "HTML cleaner and beautifier",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,2 +13,3 @@ ## HTML cleaner and beautifier

<blockquote>
<!-- List articles -->
<p><a href="foo.html">The History of Foo</a><br />

@@ -50,2 +51,3 @@ An <span color="red">informative</span> piece of <FONT FACE="ARIAL">information</FONT>.</p>

<blockquote>
<!-- List articles -->
<p>

@@ -65,2 +67,28 @@ <a href="foo.html">The History of Foo</a><br>

If you like, you can even close the empty tags, lose the comments and get rid of that nasty presentational markup:
```javascript
var options = {
'close-empty-tags': true,
'remove-comments': true,
'add-tags-to-remove': ['table', 'tr', 'td', 'blockquote']
};
process.stdout.write(cleaner.clean(data, options) + '\n');
```
Voila!
```html
<b>Currently we have these articles available:</b>
<p>
<a href="foo.html">The History of Foo</a><br/>
An <span>informative</span> piece of information.
</p>
<p>
<a href="bar.html">A Horse Walked Into a Bar</a><br/>
The bartender said "Why the long face?"
</p>
```
## Options

@@ -77,3 +105,3 @@

Block level element tags. Line breaks are added before and after, and nested content is indented. Note: this option has no effect unless pretty print is enabled.
Block level element tags. Line breaks are added before and after, and nested content is indented. Note: this option has no effect unless pretty is set to true.

@@ -85,3 +113,3 @@ Type: Array

Adds line breaks after br tags. Note: this option has no effect unless pretty print is enabled.
Adds line breaks after br tags. Note: this option has no effect unless pretty is set to true.

@@ -100,3 +128,3 @@ Type: Boolean

Empty element tags. Used in combination with `close-empty-tags` option.
Empty element tags.

@@ -108,6 +136,6 @@ Type: Array

The string to use for indentation. e.g., a tab character or one or more spaces. A falsy value indicates that the output should not be indented.
The string to use for indentation. e.g., a tab character or one or more spaces. Note: this option has no effect unless pretty is set to true.
Type: String
Default: ` `
Default: `' '` (two spaces)

@@ -157,3 +185,3 @@ ### pretty

Type; Array
Type: Array
Default: `null`

@@ -165,3 +193,3 @@

Type; Array
Type: Array
Default: `null`

@@ -19,3 +19,7 @@ var assert = require('assert'),

assert.equal(cleaner.clean('<br />'), '<br>');
assert.equal(cleaner.clean('<hr/>'), '<hr>');
assert.equal(cleaner.clean('<br/>'), '<br>');
assert.equal(cleaner.clean('<br>'), '<br>');
assert.equal(cleaner.clean('<br />', {'close-empty-tags': true}), '<br/>');
assert.equal(cleaner.clean('<br/>', {'close-empty-tags': true}), '<br/>');
assert.equal(cleaner.clean('<br>', {'close-empty-tags': true}), '<br/>');

@@ -26,2 +30,3 @@ // test that legacy attributes are removed

// test that comments are removed
assert.equal(cleaner.clean('foo<!-- bar -->'), 'foo<!-- bar -->');
assert.equal(cleaner.clean('foo<!-- bar -->', {'remove-comments': true}), 'foo');

@@ -31,8 +36,14 @@

assert.equal(cleaner.clean('foo<div></div>foo'), 'foo\n<div>\n</div>\nfoo');
assert.equal(cleaner.clean('foo<div></div>foo', {'pretty': false}), 'foo<div></div>foo');
// test that line break is added after br element tag
assert.equal(cleaner.clean('foo<br>foo'), 'foo<br>\nfoo');
assert.equal(cleaner.clean('foo<br>foo', {'break-after-br': false}), 'foo<br>foo');
assert.equal(cleaner.clean('foo<br>foo', {'pretty': false}), 'foo<br>foo');
// test that nested tags are indented after block element tags
assert.equal(cleaner.clean('<div>\nbar</div>'), '<div>\n bar\n</div>');
assert.equal(cleaner.clean('<div>bar</div>'), '<div>\n bar\n</div>');
assert.equal(cleaner.clean('<div><div>bar</div></div>'), '<div>\n <div>\n bar\n </div>\n</div>');
assert.equal(cleaner.clean('<div>bar</div>', {'indent': ' '}), '<div>\n bar\n</div>');
assert.equal(cleaner.clean('<div>bar</div>', {'pretty': false}), '<div>bar</div>');

@@ -39,0 +50,0 @@ // test that output is trimmed

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc