How to use domhandler - 10 common examples

To help you get started, we’ve selected a few domhandler 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 2youyou2 / raphael-example / assets / raphael / component / optional / R.svg.js View on Github external
}

        var svg = $('svg')[0];
        parseNode(svg, this);

        this.flipY = true;
    },
};


// hack for jsb, not use __proto__
var DomHandler = require('domhandler');
var NodePrototype = require("domhandler/lib/node");
var ElementPrototype = require("domhandler/lib/element");

DomHandler.prototype._addDomElement = function(element){
    var parent = this._tagStack[this._tagStack.length - 1];
    var siblings = parent ? parent.children : this.dom;
    var previousSibling = siblings[siblings.length - 1];

    element.next = null;

    if(this._options.withStartIndices){
        element.startIndex = this._parser.startIndex;
    }

    if (this._options.withDomLvl1) {

        var originElement = element;
        element = Object.create(element.type === "tag" ? ElementPrototype : NodePrototype);
        for (var k in originElement) {
            element[k] = originElement[k];
github ng-alain / delon / packages / schematics / ng-update / dom / dom.service.ts View on Github external
replace(html: string, rules: ConvertAction[], callback: (dom: VDom[], count: number) => void) {
    this.rules = rules;
    this.count = 0;
    const handler = new DomHandler((error, dom) => {
      if (error) {
        callback(null!, 0);
        return;
      }

      this.dom = dom;
      this.parseRule();

      callback(this.dom, this.count);
    });

    const parser = new htmlparser2.Parser(handler, {
      lowerCaseTags: false,
      lowerCaseAttributeNames: false,
      // tslint:disable-next-line: deprecation
    } as htmlparser2.ParserOptions);
github DefinitelyTyped / DefinitelyTyped / types / domhandler / domhandler-tests.ts View on Github external
import { DomHandler, DomHandlerOptions, Node, DomElement } from "domhandler";

const handler = new DomHandler((error: Error, dom: DomElement[]) => {
    if (error)
    	console.error('There has been an error...');
    else
        console.log(dom);
});
handler.ontext = (data: string) => { console.log(data); };
handler.onreset = () => { console.log('We have a reset.'); };
handler.onerror = (error: Error) => { console.error(error); };
handler.onopentag = (name: string, attribs: { [s: string]: string }) => { console.log(name, attribs); };

const dho: DomHandlerOptions = { normalizeWhitespace: true, withDomLvl1: true, withEndIndices: true, withStartIndices: true };
github juffalow / pentest-tool-lite / src / functions / parseHtml.ts View on Github external
return new Promise((resolve, reject) => {
    const handler = new DomHandler((error, dom) => {
      resolve({
        html: dom,
        url: result.url,
      });
    });
    const parser = new Parser(handler, {lowerCaseAttributeNames: true});
    parser.write(result.body);
    parser.end();
  });
}
github fb55 / node-cornet / index.js View on Github external
var DomHandler = require("domhandler"),
    DomUtils = require("domutils"),
    CSSselect = require("CSSselect");

function Handler(options){
	if(!(this instanceof Handler)) return new Handler(options);
	var that = this;
	DomHandler.call(this, function(e, dom){
		that.emit("dom", dom);
	}, options, function(elem){
		that.emit("element", elem);
	});
}

require("util").inherits(Handler, require("events").EventEmitter);
Object.getOwnPropertyNames(DomHandler.prototype).forEach(function(name){
	Handler.prototype[name] = DomHandler.prototype[name];
});

Handler.prototype.select = function(selector, cb){
	if(typeof selector === "string"){
		selector = CSSselect.parse(selector);
	}
	function onElem(elem){
		if(selector(elem)) cb(elem);
	}
	this.on("element", onElem);
	return onElem;
};

Handler.prototype.remove = function(selector){
	return this.select(selector, DomUtils.removeElement);
github fb55 / node-cornet / index.js View on Github external
function Handler(options){
	if(!(this instanceof Handler)) return new Handler(options);
	var that = this;
	DomHandler.call(this, function(e, dom){
		that.emit("dom", dom);
	}, options, function(elem){
		that.emit("element", elem);
	});
}
github fb55 / htmlparser2 / lib / FeedHandler.js View on Github external
tmp;

                item = item.children;

                addConditionally(entry, "id", "guid", item);
                addConditionally(entry, "title", "title", item);
                addConditionally(entry, "link", "link", item);
                addConditionally(entry, "description", "description", item);
                if ((tmp = fetch("pubDate", item)))
                    entry.pubDate = new Date(tmp);
                return entry;
            });
        }
    }
    this.dom = feed;
    DomHandler.prototype._handleCallback.call(
        this,
        feedRoot ? null : Error("couldn't find root of feed")
    );
};
github Rainbox-dev / DuAEF_Duik / Release / Duik-API / src-doc / tui-jsdoc-template / node_modules / htmlparser2 / lib / FeedHandler.js View on Github external
tmp;

                item = item.children;

                addConditionally(entry, "id", "guid", item);
                addConditionally(entry, "title", "title", item);
                addConditionally(entry, "link", "link", item);
                addConditionally(entry, "description", "description", item);
                if ((tmp = fetch("pubDate", item)))
                    entry.pubDate = new Date(tmp);
                return entry;
            });
        }
    }
    this.dom = feed;
    DomHandler.prototype._handleCallback.call(
        this,
        feedRoot ? null : Error("couldn't find root of feed")
    );
};
github fb55 / node-cornet / index.js View on Github external
Object.getOwnPropertyNames(DomHandler.prototype).forEach(function(name){
	Handler.prototype[name] = DomHandler.prototype[name];
});
github AndriySvyryd / UnicornHack / src / UnicornHack.Web / ClientApp / src / components / MetadataDisplay.tsx View on Github external
export function parseMetadata(input: string): React.ReactNode[] {
    const handler = new DomHandler(null as any);
    new Parser(handler).end(input);

    return processNodes((handler as any).dom);
}

domhandler

Handler for htmlparser2 that turns pages into a dom

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

78 / 100
Full package analysis