lib/HTMLParser.js
function before_html_mode(t,value,arg3,arg4) {
    var elt;
    switch(t) {
    case 1: // TEXT
      value = value.replace(LEADINGWS, ""); // Ignore spaces
      if (value.length === 0) return; // Are we done?
      break; // Handle anything non-space text below
    case 5: // DOCTYPE
      /* ignore the token */
      return;
    case 4: // COMMENT
      doc._appendChild(doc.createComment(value));
      return;
    case 2: // TAG
      if (value === "html") {
        elt = createHTMLElt(doc, value, arg3);
        stack.push(elt);
        doc.appendChild(elt);
        // XXX: handle application cache here
        parser = before_head_mode;
        return;
      }
      break;
    case 3: // ENDTAG
      switch(value) {
      case "html":
      case "head":
      case "body":
      case "br":
        break;  // fall through on these
      default:
        return; // ignore most end tags
      }
    }

    // Anything that didn't get handled above is handled like this:
    elt = createHTMLElt(doc, "html", null);
    stack.push(elt);
    doc.appendChild(elt);
    // XXX: handle application cache here
    parser = before_head_mode;
    parser(t,value,arg3,arg4);
  }
function before_html_mode(t,value,arg3,arg4) {
    var elt;
    switch(t) {
    case 1: // TEXT
      value = value.replace(LEADINGWS, ""); // Ignore spaces
      if (value.length === 0) return; // Are we done?
      break; // Handle anything non-space text below
    case 5: // DOCTYPE
      /* ignore the token */
      return;
    case 4: // COMMENT
      doc._appendChild(doc.createComment(value));
      return;
    case 2: // TAG
      if (value === "html") {
        elt = createHTMLElt(doc, value, arg3);
        stack.push(elt);
        doc.appendChild(elt);
        // XXX: handle application cache here
        parser = before_head_mode;
        return;
      }
      break;
    case 3: // ENDTAG
      switch(value) {
      case "html":
      case "head":
      case "body":
      case "br":
        break;  // fall through on these
      default:
        return; // ignore most end tags
      }
    }

    // Anything that didn't get handled above is handled like this:
    elt = createHTMLElt(doc, "html", null);
    stack.push(elt);
    doc.appendChild(elt);
    // XXX: handle application cache here
    parser = before_head_mode;
    parser(t,value,arg3,arg4);
  }
function before_html_mode ( t , value , arg3 , arg4 ) { var elt ; switch ( t ) { case 1 : // TEXT value = value . replace ( LEADINGWS , "" ) ; // Ignore spaces if ( value . length === 0 ) return ; // Are we done? break ; // Handle anything non-space text below case 5 : // DOCTYPE /* ignore the token */ return ; case 4 : // COMMENT doc . _appendChild ( doc . createComment ( value ) ) ; return ; case 2 : // TAG if ( value === "html" ) { elt = createHTMLElt ( doc , value , arg3 ) ; stack . push ( elt ) ; doc . appendChild ( elt ) ; // XXX: handle application cache here parser = before_head_mode ; return ; } break ; case 3 : // ENDTAG switch ( value ) { case "html" : case "head" : case "body" : case "br" : break ; // fall through on these default : return ; // ignore most end tags } } // Anything that didn't get handled above is handled like this: elt = createHTMLElt ( doc , "html" , null ) ; stack . push ( elt ) ; doc . appendChild ( elt ) ; // XXX: handle application cache here parser = before_head_mode ; parser ( t , value , arg3 , arg4 ) ; }
11.2.5.4.2 The "before html" insertion mode
11 . 2 . 5 . 4 . 2 The before html insertion mode