lib/HTMLParser.js
function before_head_mode(t,value,arg3,arg4) {
    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
      insertComment(value);
      return;
    case 2: // TAG
      switch(value) {
      case "html":
        in_body_mode(t,value,arg3,arg4);
        return;
      case "head":
        var elt = insertHTMLElement(value, arg3);
        head_element_pointer = elt;
        parser = in_head_mode;
        return;
      }
      break;
    case 3: // ENDTAG
      switch(value) {
      case "html":
      case "head":
      case "body":
      case "br":
        break;
      default:
        return; // ignore most end tags
      }
    }

    // If not handled explicitly above
    before_head_mode(TAG, "head", null); // create a head tag
    parser(t, value, arg3, arg4); // then try again with this token
  }
function before_head_mode(t,value,arg3,arg4) {
    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
      insertComment(value);
      return;
    case 2: // TAG
      switch(value) {
      case "html":
        in_body_mode(t,value,arg3,arg4);
        return;
      case "head":
        var elt = insertHTMLElement(value, arg3);
        head_element_pointer = elt;
        parser = in_head_mode;
        return;
      }
      break;
    case 3: // ENDTAG
      switch(value) {
      case "html":
      case "head":
      case "body":
      case "br":
        break;
      default:
        return; // ignore most end tags
      }
    }

    // If not handled explicitly above
    before_head_mode(TAG, "head", null); // create a head tag
    parser(t, value, arg3, arg4); // then try again with this token
  }
function before_head_mode ( t , value , arg3 , arg4 ) { 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 insertComment ( value ) ; return ; case 2 : // TAG switch ( value ) { case "html" : in_body_mode ( t , value , arg3 , arg4 ) ; return ; case "head" : var elt = insertHTMLElement ( value , arg3 ) ; head_element_pointer = elt ; parser = in_head_mode ; return ; } break ; case 3 : // ENDTAG switch ( value ) { case "html" : case "head" : case "body" : case "br" : break ; default : return ; // ignore most end tags } } // If not handled explicitly above before_head_mode ( TAG , "head" , null ) ; // create a head tag parser ( t , value , arg3 , arg4 ) ; // then try again with this token }
11.2.5.4.3 The "before head" insertion mode
11 . 2 . 5 . 4 . 3 The before head insertion mode