How to use the htmlparser2.Parser.prototype function in htmlparser2

To help you get started, we’ve selected a few htmlparser2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecomfe / okam / packages / okam-build / lib / processor / template / parser / index.js View on Github external
*/

'use strict';

const util = require('util');
const {DomHandler, Parser, ElementType} = require('htmlparser2');

const DEFAULT_OPTIONS = {
    lowerCaseTags: true,
    recognizeSelfClosing: true,
    lowerCaseAttributeNames: false
};

const rawOnattribend = Parser.prototype.onattribend;
const rawOnattribdata = Parser.prototype.onattribdata;
const rawOnselfclosingtag = Parser.prototype.onselfclosingtag;
const rawOnclosetag = Parser.prototype.onclosetag;

class TemplateParser {
    constructor(...args) {
        Parser.apply(this, args);
    }

    onattribdata(...args) {
        rawOnattribdata.apply(this, args);
        this._hasAttrValue = true;
    }

    onattribend(...args) {
        if (!this._hasAttrValue) {
            // reset boolean value
            this._attribvalue = true;
github yhatt / markdown-it-incremental-dom / test / markdown-it-incremental-dom.js View on Github external
beforeEach(() => {
          spy = jest.spyOn(Parser.prototype, 'write')
        })
        afterEach(() => spy.mockRestore())
github ecomfe / okam / packages / okam-build / lib / processor / template / parser / index.js View on Github external
* @file Template parser
 * @author sparklewhy@gmail.com
 */

'use strict';

const util = require('util');
const {DomHandler, Parser, ElementType} = require('htmlparser2');

const DEFAULT_OPTIONS = {
    lowerCaseTags: true,
    recognizeSelfClosing: true,
    lowerCaseAttributeNames: false
};

const rawOnattribend = Parser.prototype.onattribend;
const rawOnattribdata = Parser.prototype.onattribdata;
const rawOnselfclosingtag = Parser.prototype.onselfclosingtag;
const rawOnclosetag = Parser.prototype.onclosetag;

class TemplateParser {
    constructor(...args) {
        Parser.apply(this, args);
    }

    onattribdata(...args) {
        rawOnattribdata.apply(this, args);
        this._hasAttrValue = true;
    }

    onattribend(...args) {
        if (!this._hasAttrValue) {