How to use node-html-parser - 10 common examples

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 pulumi / docs / scripts / link_linter.js View on Github external
rawAttrs: link.rawAttrs,
            validId: isValidId,
        };
    }
    return null;
};

// Build a list of files to lint from the layouts directory.
const filesToLint = buildFileList("../layouts");

const linkLintErrors = {};

for (let i = 0; i < filesToLint.length; i++) {
    const fileToLint = filesToLint[i];
    const html = fs.readFileSync(fileToLint, "utf8");
    const parsedHtml = parse.parse(html);
    const links = parsedHtml.querySelectorAll("a").map(validateTrackingLink)
                  .filter(function(result) { return result !== null });
    if (links.length > 0) {
        linkLintErrors[fileToLint] = links;
    }
}

const filesWithErrors = Object.keys(linkLintErrors);

function createErrorOutput(error) {
    let msg = "";
    if (!error.validId) {
        msg += "Link missing 'data-tracking-id' attribute.";
    }
    msg += "\n";
    return msg;
github wrussell1999 / food-flex-discord / web / functions / index.js View on Github external
fs.readFile('views/leaderboard.html', 'utf8', (err, html) => {
        if (err) {
            throw err;
        }

        var sort_array = [];
        for (var key in data) {
            sort_array.push({ key: key, score: data[key].score, nick: data[key].nick });
        }
        sort_array.sort(function (x, y) { return y.score - x.score });
        
        const root = parse(html);
        const tbody = root.querySelector('tbody');
        for (var i = 0; i < sort_array.length; i++) {
            var item = data[sort_array[i].key];
            const table = `
            
                ${i + 1}
                ${item.nick}
                ${item.score}
            
            `
            tbody.appendChild(table);
        }        
        // add term date
        res.status(200).send(root.toString());
    });
});
github ml5js / ml5-examples / scripts / create-examples-index.js View on Github external
const fs = require('fs');
const path = require('path');
const recursive = require("recursive-readdir");
const { parse } = require('node-html-parser');

const baseurl = path.resolve(__dirname, "..");

const ghUrl = 'https://ml5js.github.io/ml5-examples'
const indexPath = `${baseurl}/public/index.html`

let $index = parse(fs.readFileSync(indexPath, 'utf8'));
let $myLinks = $index.querySelector('#myLinks')
// clear the content;
$myLinks.set_content("")

const p5Examples = getReferences(`${baseurl}/p5js`, 'p5js', ghUrl);
const plainJsExamples = getReferences(`${baseurl}/javascript`, 'javascript', ghUrl);
const d3Examples = getReferences(`${baseurl}/d3`, 'd3', ghUrl);


const p5Header = `<div class="category-header"><h2>ml5 examples with p5.js</h2></div>`
const jsHeader = `<div class="category-header"><h2>ml5 examples with plain javascript</h2></div>`
const d3Header = `<div class="category-header"><h2>ml5 examples with d3</h2></div>`

// p5 examples
$myLinks.appendChild(p5Header);
addToDom(p5Examples, $myLinks)
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 interfacewerk / iwerk-angular-ui / scripts / generate-examples.js View on Github external
matches.forEach(absPath =&gt; {
      const content = fs.readFileSync(absPath);
      const root = parse(`${content}`);
      const codes = root.querySelectorAll('docs-code');
      codes.map(c =&gt; c.attributes).filter(a =&gt; a.path).forEach(c =&gt; {
        const path = c.path;
        const completePath = findMatchingFile(allFiles, path);
        if (!completePath) {
          console.error(`ERROR: could not find a file for the short path ${path}`);
        } else {
          object[path] = fs.readFileSync(completePath).toString().replace(/from 'src\/public_api'/g, `from 'iwerk-angular-ui'`);
        }
      });
    });
    fs.writeFileSync(path.join(projectRootPath, 'assets/examples.json'), JSON.stringify(object));
github rolling-scopes / rsschool-app / serverless / github-task-checker / checkExternalTask / getCodecademy.ts View on Github external
export default async (username: string): Promise =&gt; {
  if (!username) {
    return {
      result: false,
      details: 'No Codecademy account provided',
    };
  }

  const url = `${URL}${username}`;

  try {
    const page = (await axios.get(url)).data;
    const dom = parse(page) as HTMLElement;

    const skills = dom
      .querySelectorAll('.contentContainer__3yhRX203mZ5d3LM9QdQ1lj')
      .map(skill =&gt; {
        const name = skill.querySelector('.title__3niw5hwoyf-vt1SazvY5Gd').childNodes[0].rawText;
        const isPassed =
          skill.querySelector('.description__5pwX6COkDGktqHdkXYDuu').childNodes[0].rawText === 'Completed';

        return { name, isPassed };
      })
      .filter(skill =&gt; TASKS.includes(skill.name) &amp;&amp; skill.isPassed);

    console.log('Codecademy skills =&gt;', JSON.stringify(skills));

    return {
      result: skills.length === TASKS.length,
github spderosso / deja-vu / packages / schematics / src / component / index.ts View on Github external
}

    const title = `${strings.capitalize(options.type)} ` +
      `${strings.capitalize(options.entityName)}`;
    const componentHtml =
      `  <h2>${title}</h2>\n` +
      `  &lt;${componentComponentSelector}&gt;\n`;

    const container = root.querySelector('div.container');
    if (!container) {
      console.log('Could not find div with class container, ' +
        `skipping update to ${filePath}`);
      return tree;
    }

    container.appendChild(new TextNode(componentHtml));
    tree.overwrite(filePath, root.toString());

    return tree;
  };
}
github ml5js / ml5-examples / scripts / update-ml5-reference.js View on Github external
function updateMl5Reference(filePath, ml5src){
    let pos;
    let el = parse(fs.readFileSync(filePath, 'utf8'));
    let scripts = el.querySelectorAll('script')
    let selectedRef = scripts.find((item, idx) => {
        if(item.rawAttrs.includes('ml5')){
            pos = idx;
            return item
        }
    })
    selectedRef.rawAttrs = ml5src
    scripts[pos] = selectedRef;

    fs.writeFileSync(filePath, el, 'utf8');
}
github spacemeowx2 / LiveHelper / src / utils.ts View on Github external
export function parseHTML(html: string) {
  return (parse(html) as (HTMLElement & {
    valid: boolean;
  }))
}

node-html-parser

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

MIT
Latest version published 28 days ago

Package Health Score

82 / 100
Full package analysis