How to use the htmlparser2.DefaultHandler 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 bigeasy / stencil / stencil.js View on Github external
}, function (body) {
            var handler = new htmlparser.DefaultHandler()
            var tokenizer = new (require('./parser'))
            var parser = new htmlparser.Parser(handler);
            tokenizer._cbs = new TokenizerProxy(parser._tokenizer._cbs)
            parser._tokenizer = tokenizer
            parser.parseComplete(body)
            //console.log('=======')
            // great. now it's time for a serializer.
            //console.log( domutils.getOuterHTML(handler.dom[0]))
            //console.log('=======')
            //console.log(require('util').inspect(handler.dom[0], false, null))
            var actual = new (xmldom.DOMParser)().parseFromString('')
            actual.documentElement.parentNode.removeChild(actual.documentElement)
            createXMLTemplate(actual, handler.dom[0])
            // Why? Because. Because namespaces. Hateful namespaces.
            var actual = new (xmldom.DOMParser)().parseFromString(actual.toString())
github basisjs / basisjs-tools / tests / build / html / fetchFiles.spec.js View on Github external
var htmlparser = require("htmlparser2");
var fetchFiles = require('../../../build/html/fetchFiles.js');

var handler = new htmlparser.DefaultHandler();
var parser = new htmlparser.Parser(handler,  { lowerCaseTags: true });

function getAst(content){
  parser.parseComplete(content);
  return handler.dom;
}

function getFlowData(ast, spy){
  return {
    inputDir: '/some/dir',
    inputFile:{
      ast: ast
    },
    files: {
      add: spy
    },
github sourceboat / pug-lint-vue / lib / linter.js View on Github external
extractFileTemplates (fileData) {
    let templates = []

    const handler = new htmlparser.DefaultHandler((error, dom) => {
      if (error) {
        return console.log(error)
      }

      const $ = cheerio.load(dom)
      templates = templates.concat($('template[lang="pug"]').text())
    })

    var parser = new htmlparser.Parser(handler)
    parser.parseComplete(fileData)
    return templates
  }
}
github sourceboat / sass-lint-vue / lib / linter.js View on Github external
extractFileTemplates (fileData) {
    let templates = []

    const handler = new htmlparser.DefaultHandler((error, dom) => {
      if (error) {
        return console.log(error)
      }

      const $ = cheerio.load(dom)
      const scssTemplate = $('style[lang="scss"]').text()
      const sassTemplate = $('style[lang="sass"]').text()

      if (scssTemplate.length) {
        templates.push({
          content: scssTemplate,
          format: 'scss',
          lineOffset: this.getLineOffset(scssTemplate, $.text())
        })
      }
      if (sassTemplate.length) {
github bigeasy / stencil / html / parser.js View on Github external
function html (document, html) {
    var handler = new htmlparser.DefaultHandler(),
        frag = document.createDocumentFragment();
    var parser = new htmlparser.Parser(handler);
    parser.parseComplete(html);
    copy(document, frag, handler.dom);
    return frag;
}
github werk85 / node-html-to-text / lib / html-to-text.js View on Github external
noAnchorUrl: true,
    baseElement: 'body',
    returnDomByDefault: true,
    format: {},
    decodeOptions: {
      isAttributeValue: false,
      strict: false
    },
    longWordSplit: {
      wrapCharacters: [],
      forceWrapOnLimit: false
    },
    unorderedListItemPrefix: ' * '
  }, options || {});

  var handler = new htmlparser.DefaultHandler(function (error, dom) {

  }, {
    verbose: true
  });
  new htmlparser.Parser(handler).parseComplete(html);

  options.lineCharCount = 0;

  var result = '';
  var baseElements = Array.isArray(options.baseElement) ? options.baseElement : [options.baseElement];
  for (var idx = 0; idx < baseElements.length; ++idx) {
    result += walk(filterBody(handler.dom, options, baseElements[idx]), options);
  }
  return trimEnd(result);
}
github macacajs / NoSmoke / lib / crawler / ocr-impl / hocr-to-json.js View on Github external
Hocr.prototype.parse = function() {
  var handler, parser, that;
  that = this;
  handler = new htmlparser.DefaultHandler(function(error, dom) {
    if (error) {
      return that.callback(error, false);
    } else {
      that.toJSON(dom);
      return that.callback(false, that.result);
    }
  }, {
    verbose: false,
    ignoreWhitespace: true
  });
  parser = new htmlparser.Parser(handler);
  return parser.parseComplete(this.html);
};