<commit_before>var HtmlToDom = function(parser){
  
  if(parser && parser.write) {
    // sax parser
    
    this.appendHtmlToElement = function(html, element){

      var currentElement = element, currentLevel = 0;

      parser.onerror = function (e) {};

      parser.ontext = function (t) {
        var ownerDocument = currentElement.ownerDocument || currentElement;
        var newText = ownerDocument.createTextNode(t);
        currentElement.appendChild(newText);
      };

      parser.onopentag = function (node) {
        var nodeName  = node.name.toLowerCase(),
            document   = currentElement.ownerDocument || currentElement,
            newElement = document.createElement(nodeName),
            i          = 0,
            length     = (node.attributes && node.attributes.length) ? 
                          node.attributes.length                     :
                          0;
        for (i in node.attributes)
        {
          if (node.attributes.hasOwnProperty(i)) {
            newElement.setAttribute(i, node.attributes[i]);
          }
        }
        currentElement.appendChild(newElement);
        currentElement = newElement;
      };

      parser.onclosetag = function(node) {
        currentElement = currentElement.parentNode;
      }

      parser.write(html).close();

      return element;
    }
    
  } else if(parser && (parser.ParseHtml || parser.DefaultHandler)) {
    
    // Forgiving HTML parser
    
    if(parser.ParseHtml){
      // davglass/node-htmlparser
    } else if(parser.DefaultHandler){
      // tautologistics/node-htmlparser
      parser.ParseHtml = function(rawHtml){
        var handler = new this.DefaultHandler();
        var parser = new this.Parser(handler);
        parser.parseComplete(rawHtml);
        return handler.dom;
      }
    }
    
    this.appendHtmlToElement = function(html, element){

      if (typeof html !== 'string') {
          html +='';
      }
      
      var parsed = parser.ParseHtml(html);

      for (var i = 0; i < parsed.length; i++) {
          setChild.call(element, parsed[i]);
      }

      return element;
      
    }
    
  } else if(parser && parser.newPhase) { /* HTML5 parser */
    this.appendHtmlToElement = function(html, element) {
      if(typeof html !== 'string') html += '';
      var p = new parser({document: element.ownerDocument});
      var tree = p.parse_fragment(html, element);
      throw new Error("Fixme!");
    }
  } else {
    
    this.appendHtmlToElement = function(){
      var sys = require('sys');<commit_msg>Solidify detection of HTML5 parser<commit_after>var HtmlToDom = function(parser){
  
  if(parser && parser.write) {
    // sax parser
    
    this.appendHtmlToElement = function(html, element){

      var currentElement = element, currentLevel = 0;

      parser.onerror = function (e) {};

      parser.ontext = function (t) {
        var ownerDocument = currentElement.ownerDocument || currentElement;
        var newText = ownerDocument.createTextNode(t);
        currentElement.appendChild(newText);
      };

      parser.onopentag = function (node) {
        var nodeName  = node.name.toLowerCase(),
            document   = currentElement.ownerDocument || currentElement,
            newElement = document.createElement(nodeName),
            i          = 0,
            length     = (node.attributes && node.attributes.length) ? 
                          node.attributes.length                     :
                          0;
        for (i in node.attributes)
        {
          if (node.attributes.hasOwnProperty(i)) {
            newElement.setAttribute(i, node.attributes[i]);
          }
        }
        currentElement.appendChild(newElement);
        currentElement = newElement;
      };

      parser.onclosetag = function(node) {
        currentElement = currentElement.parentNode;
      }

      parser.write(html).close();

      return element;
    }
    
  } else if(parser && (parser.ParseHtml || parser.DefaultHandler)) {
    
    // Forgiving HTML parser
    
    if(parser.ParseHtml){
      // davglass/node-htmlparser
    } else if(parser.DefaultHandler){
      // tautologistics/node-htmlparser
      parser.ParseHtml = function(rawHtml){
        var handler = new this.DefaultHandler();
        var parser = new this.Parser(handler);
        parser.parseComplete(rawHtml);
        return handler.dom;
      }
    }
    
    this.appendHtmlToElement = function(html, element){

      if (typeof html !== 'string') {
          html +='';
      }
      
      var parsed = parser.ParseHtml(html);

      for (var i = 0; i < parsed.length; i++) {
          setChild.call(element, parsed[i]);
      }

      return element;
      
    }
    
  } else if(parser && parser.moduleName == 'HTML5') { /* HTML5 parser */
    this.appendHtmlToElement = function(html, element) {
      if(typeof html !== 'string') html += '';
      var p = new parser.Parser({document: element.ownerDocument});
      var tree = p.parse_fragment(html, element);
      throw new Error("Fixme!");
    }
  } else {
    
    this.appendHtmlToElement = function(){
      var sys = require('sys');
{'fraction_non_alphanumeric': 0.11663108868620221, 'fraction_numerical': 0.0023287405394915583, 'mean_word_length': 2.0282021151586367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805199', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1392, 'n_words': 288}