How to use the node-html-parser.NodeType function in node-html-parser

To help you get started, we’ve selected a few node-html-parser 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 Half-Shot / matrix-appservice-discord / src / matrixmessageprocessor.ts View on Github external
private async walkNode(node: Parser.Node): Promise {
        if (node.nodeType === Parser.NodeType.TEXT_NODE) {
            // ignore \n between single nodes
            if ((node as Parser.TextNode).text === "\n") {
                return "";
            }
            return await this.escapeDiscord((node as Parser.TextNode).text);
        } else if (node.nodeType === Parser.NodeType.ELEMENT_NODE) {
            const nodeHtml = node as Parser.HTMLElement;
            switch (nodeHtml.tagName) {
                case "em":
                case "i":
                    return `*${await this.walkChildNodes(nodeHtml)}*`;
                case "strong":
                case "b":
                    return `**${await this.walkChildNodes(nodeHtml)}**`;
                case "u":
                    return `__${await this.walkChildNodes(nodeHtml)}__`;
github Half-Shot / matrix-appservice-discord / src / matrixmessageprocessor.ts View on Github external
await Util.AsyncForEach(node.childNodes, async (child) => {
            if (types.length && (
                child.nodeType === Parser.NodeType.TEXT_NODE
                || !types.includes((child as Parser.HTMLElement).tagName)
            )) {
                return;
            }
            replies.push(await this.walkNode(child));
        });
        return replies;

node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.

MIT
Latest version published 8 months ago

Package Health Score

78 / 100
Full package analysis