How to use the node-html-parser.parse 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 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 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 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;
  }))
}
github The-Quill / SE-Chat-Terminal / chat_modules / core.js View on Github external
async function loadRooms(domain, page = 1) {
  if (!domainVars.doneWithRooms.hasOwnProperty(domain)) {
    domainVars.doneWithRooms[domain] = false
  }
  if (domainVars.doneWithRooms[domain]) return
  const res = await request(`https://chat.${domain}.com/?tab=all&sort=active&page=${page}`)
  const root = parse(res)
  const rooms = root.querySelectorAll('.roomcard').map(room => ({
    id: +room.querySelector('.room-name a').rawAttributes.href.replace(/\/rooms\/(\d+)\/(?:.+)?/, '$1'),
    name: room.querySelector('span.room-name').attributes.title,
    users: +room.querySelector('.room-users').rawAttributes.title.replace(/ users? present/, '')
  }))
  if (!domainVars.rooms.hasOwnProperty(domain)) {
    domainVars.rooms[domain] = {}
  }
  const newRooms = rooms
  .filter(room => !domainVars.rooms[domain].hasOwnProperty(room.id))

  domainVars.doneWithRooms[domain] = newRooms.length === 0
  newRooms
  .forEach(room => domainVars.rooms[domain][room.id] = room)
  return newRooms
}

node-html-parser

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

MIT
Latest version published 1 month ago

Package Health Score

82 / 100
Full package analysis