Socket
Socket
Sign inDemoInstall

node-html-parser

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-html-parser - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

61

dist/main.js

@@ -1087,15 +1087,30 @@ var __extends = (this && this.__extends) || (function () {

};
var kBlockTextElements = {
script: true,
SCRIPT: true,
noscript: true,
NOSCRIPT: true,
style: true,
STYLE: true,
pre: true,
PRE: true
};
var frameflag = 'documentfragmentcontainer';
function parse(data, options) {
if (options === void 0) { options = {}; }
if (options === void 0) { options = { lowerCaseTagName: false, comment: false }; }
var elements = options.blockTextElements || {
script: true,
noscript: true,
style: true,
pre: true
};
var element_names = Object.keys(elements);
var kBlockTextElements = element_names.map(function (it) {
return new RegExp(it, 'i');
});
var kIgnoreElements = element_names.filter(function (it) {
return elements[it];
}).map(function (it) {
return new RegExp(it, 'i');
});
function element_should_be_ignore(tag) {
return kIgnoreElements.some(function (it) {
return it.test(tag);
});
}
function is_block_text_element(tag) {
return kBlockTextElements.some(function (it) {
return it.test(tag);
});
}
var root = new HTMLElement(null, {});

@@ -1149,3 +1164,3 @@ var currentParent = root;

stack.push(currentParent);
if (kBlockTextElements[match[2]]) {
if (is_block_text_element(match[2])) {
// a little test to find next </script> or </style> ...

@@ -1159,13 +1174,15 @@ var closeMarkup_1 = "</" + match[2] + ">";

})();
var text = void 0;
if (index === -1) {
// there is no matching ending for the text element.
text = data.substr(kMarkupPattern.lastIndex);
if (element_should_be_ignore(match[2])) {
var text = void 0;
if (index === -1) {
// there is no matching ending for the text element.
text = data.substr(kMarkupPattern.lastIndex);
}
else {
text = data.substring(kMarkupPattern.lastIndex, index);
}
if (text.length > 0) {
currentParent.appendChild(new text_1.default(text));
}
}
else {
text = data.substring(kMarkupPattern.lastIndex, index);
}
if (text.length > 0) {
currentParent.appendChild(new text_1.default(text));
}
if (index === -1) {

@@ -1172,0 +1189,0 @@ lastTextPos = kMarkupPattern.lastIndex = data.length + 1;

@@ -153,4 +153,7 @@ import Node from './node';

export interface Options {
lowerCaseTagName?: boolean;
comment?: boolean;
lowerCaseTagName: boolean;
comment: boolean;
blockTextElements: {
[tag: string]: boolean;
};
}

@@ -163,6 +166,6 @@ /**

*/
export declare function parse(data: string, options?: Options): HTMLElement & {
export declare function parse(data: string, options?: Partial<Options>): HTMLElement & {
valid: boolean;
};
export declare function parse(data: string, options?: Options & {
export declare function parse(data: string, options?: Partial<Options> & {
noFix: false;

@@ -172,3 +175,3 @@ }): HTMLElement & {

};
export declare function parse(data: string, options?: Options & {
export declare function parse(data: string, options?: Partial<Options> & {
noFix: true;

@@ -175,0 +178,0 @@ }): (HTMLElement | TextNode) & {

@@ -701,15 +701,30 @@ "use strict";

};
var kBlockTextElements = {
script: true,
SCRIPT: true,
noscript: true,
NOSCRIPT: true,
style: true,
STYLE: true,
pre: true,
PRE: true
};
var frameflag = 'documentfragmentcontainer';
function parse(data, options) {
if (options === void 0) { options = {}; }
if (options === void 0) { options = { lowerCaseTagName: false, comment: false }; }
var elements = options.blockTextElements || {
script: true,
noscript: true,
style: true,
pre: true
};
var element_names = Object.keys(elements);
var kBlockTextElements = element_names.map(function (it) {
return new RegExp(it, 'i');
});
var kIgnoreElements = element_names.filter(function (it) {
return elements[it];
}).map(function (it) {
return new RegExp(it, 'i');
});
function element_should_be_ignore(tag) {
return kIgnoreElements.some(function (it) {
return it.test(tag);
});
}
function is_block_text_element(tag) {
return kBlockTextElements.some(function (it) {
return it.test(tag);
});
}
var root = new HTMLElement(null, {});

@@ -763,3 +778,3 @@ var currentParent = root;

stack.push(currentParent);
if (kBlockTextElements[match[2]]) {
if (is_block_text_element(match[2])) {
// a little test to find next </script> or </style> ...

@@ -773,13 +788,15 @@ var closeMarkup_1 = "</" + match[2] + ">";

})();
var text = void 0;
if (index === -1) {
// there is no matching ending for the text element.
text = data.substr(kMarkupPattern.lastIndex);
if (element_should_be_ignore(match[2])) {
var text = void 0;
if (index === -1) {
// there is no matching ending for the text element.
text = data.substr(kMarkupPattern.lastIndex);
}
else {
text = data.substring(kMarkupPattern.lastIndex, index);
}
if (text.length > 0) {
currentParent.appendChild(new text_1.default(text));
}
}
else {
text = data.substring(kMarkupPattern.lastIndex, index);
}
if (text.length > 0) {
currentParent.appendChild(new text_1.default(text));
}
if (index === -1) {

@@ -786,0 +803,0 @@ lastTextPos = kMarkupPattern.lastIndex = data.length + 1;

{
"name": "node-html-parser",
"version": "1.3.2",
"version": "1.3.3",
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",

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

@@ -78,2 +78,8 @@ # Fast HTML Parser [![NPM version](https://badge.fury.io/js/node-html-parser.png)](http://badge.fury.io/js/node-html-parser) [![Build Status](https://travis-ci.org/taoqf/node-html-parser.svg?branch=master)](https://travis-ci.org/taoqf/node-html-parser)

comment: false // retrieve comments (hurt performance slightly)
blockTextElements: {
script: true, // keep text content when parsing
noscript: true, // keep text content when parsing
style: true, // keep text content when parsing
pre: true // keep text content when parsing
}
}

@@ -80,0 +86,0 @@ ```

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