How to use the htmlparser2.DomUtils 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 xiandanin / magnetW / src / main / repository.js View on Github external
async function requestParseSearchItems ({requestOptions, xpath}) {
  try {
    const rsp = await request(requestOptions)

    // 用htmlparser2转换一次再解析
    let outerHTML = htmlparser2.DomUtils.getOuterHTML(htmlparser2.parseDOM(rsp))
    const document = domParser.parseFromString(outerHTML)
    return {items: parseDocument(document, xpath)}
  } catch (e) {
    console.error('解析失败', e)
    return {err: e}
  }
}
github mrodal / vue-inheritance-loader / src / index.js View on Github external
let extendBlock = extensions.find(node => node.attribs[options.EXT_POINT_REF_ATTR] === extPoint.attribs[options.EXT_POINT_NAME_ATTR]);

                // If a extend block matching the extension point was found, replace the point's content with the extend block's
                if (extendBlock) {
                  extPoint.children = extendBlock.children;

                  // Change extension point tag to a template tag
                  extPoint.name = 'template';
                  delete extPoint.attribs[options.EXT_POINT_NAME_ATTR];
                }
              });

              // Resolve promise with the new generated SFC
              resolve({
                source: `<template>
                           ${htmlparser.DomUtils.getOuterHTML(baseDom)}
                         </template> 
                         ${descriptorToHTML(currentDesc)}`,
                ancestorsPaths
              });
            } catch (e) {
              reject(e)
            }
          }, e =&gt; {
            reject(e)
github alibaba / rax / packages / sfc-loader / src / sfc / parser.js View on Github external
function innerHTML(dom) {
  return htmlparser.DomUtils.getOuterHTML(dom, {
    xmlMode: true
  });
}
github turbio / bracey.vim / server / htmlfile.js View on Github external
HtmlFile.prototype.webSrc = function(){
	//transform the internal html sturcture into websource only when it's requested

	var webSourceHtml = stripElements(this.parsedHtml, true);

	//and for now... just assume this is a full html document
	//this basically just adds the required css and js to the head
	//also set the index attribute
	var first = htmlparser.DomUtils.findOne(function() {return true}, webSourceHtml);

	htmlparser.DomUtils.appendChild(first, {
		type: 'script',
		name: 'script',
		attribs: {language: 'javascript'},
		children: [{
			data: HtmlFile.injectedJS,
			type: 'text'
		}]
	});
	htmlparser.DomUtils.appendChild(first, {
		type: 'style',
		name: 'style',
		children: [{
			data: HtmlFile.injectedCSS,
			type: 'text'
github pandawing / node-chrome-web-store-item-property / src / convert.js View on Github external
'use strict';
var InvalidFormatError = require('./error').InvalidFormatError;
var Promise = Promise || require('es6-promise').Promise;
var htmlparser2 = require('htmlparser2');
var DomHandler = htmlparser2.DomHandler;
var Parser = htmlparser2.Parser;
var DomUtils = htmlparser2.DomUtils;
var includes = require('array-includes');
var parseFloatWithComma = require('./parse-float-with-comma');
var keysStringToFloat = [
  'ratingCount',
  'ratingValue',
  'UserDownloads'
];

function convert(detailHtml) {
  return new Promise(function (resolve, reject) {
    var itemProps = {};
    var elementItemProp;
    var options = {};
    var handler = new DomHandler(null, options);
    new Parser(handler, options).end(detailHtml);
    var dom = handler.dom;
github mrodal / vue-inheritance-loader / src / index.js View on Github external
function findDomElementsByTagName(dom, tag) {
  return htmlparser.DomUtils.findAll(node => (node.type === 'tag' && node.name === tag), dom)
}