mnm-html-parser
v2.2.5
Published
This module returns objects that are results of a possible html string that is parsed by this class.
Downloads
8
Maintainers
Readme
The role of this module is to parse the valid html tags in a string and return an array of objects which has the following properties:
parsedResult : an array of objects, where in each item will have the value, type, and position as its properties,
- each of the objects in the array will have the following properties :
- value : the parsed substring,
- type : the type of the string, whether its an html tag;
- position : zero-based indexing determining the position of the substr in the array of objects
pairedTags : an array of the valid html tags parsed and paired; each item in the array will have openingTag and closingTag as its properties; and each will have the same properties as any item in the parsedResult;
- each of the objects in the array will have the following properties :
opening
- value : the parsed substring,
- el : name of the valid element,
- parsePosition : is the same as the position used in parsedResult; we can use this to reference where the paired tags sit in the string; or maybe return an innerHTML;
closing
- value : the parsed substring,
- el : name of the valid element,
- parsePosition : is the same as the position used in parsedResult; we can use this to reference where the paired tags sit in the string; or maybe return an innerHTML;
selfClosingTags : this is just a similar array to the parsedResult; the only difference is that it is composed of only self-closing type of html;
- each item will have the same properties as any item in the parsedResult;
removedInvalidTags : this is just a similar array to the parsedResult; initial value is an empty array; and depending on whether you want to remove the invalid tags or not, it will or will not have any array element;
- each item will have the same properties as any item in the parsedResult;
Usage
const htmlParser = require("mnm-html-parser");
const parsedHtmlObject = htmlParser(htmlString);
parsedHtmlObject.initialize();
console.log(parsedHtmlObject); // returns parsedHtmlObject {parsedResult = [], pairedTags = [], selfClosingTags = [], removedInvalidTags = []}