stickshift.js
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
    if (!text) return;
    var special = builder.cm.options.specialChars, mustWrap = false;
    if (!special.test(text)) {
      builder.col += text.length;
      var content = document.createTextNode(text);
      builder.map.push(builder.pos, builder.pos + text.length, content);
      if (ie && ie_version < 9) mustWrap = true;
      builder.pos += text.length;
    } else {
      var content = document.createDocumentFragment(), pos = 0;
      while (true) {
        special.lastIndex = pos;
        var m = special.exec(text);
        var skipped = m ? m.index - pos : text.length - pos;
        if (skipped) {
          var txt = document.createTextNode(text.slice(pos, pos + skipped));
          if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
          else content.appendChild(txt);
          builder.map.push(builder.pos, builder.pos + skipped, txt);
          builder.col += skipped;
          builder.pos += skipped;
        }
        if (!m) break;
        pos += skipped + 1;
        if (m[0] == "\t") {
          var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
          var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
          txt.setAttribute("role", "presentation");
          builder.col += tabWidth;
        } else {
          var txt = builder.cm.options.specialCharPlaceholder(m[0]);
          if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
          else content.appendChild(txt);
          builder.col += 1;
        }
        builder.map.push(builder.pos, builder.pos + 1, txt);
        builder.pos++;
      }
    }
    if (style || startStyle || endStyle || mustWrap || css) {
      var fullStyle = style || "";
      if (startStyle) fullStyle += startStyle;
      if (endStyle) fullStyle += endStyle;
      var token = elt("span", [content], fullStyle, css);
      if (title) token.title = title;
      return builder.content.appendChild(token);
    }
    builder.content.appendChild(content);
  }
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
    if (!text) return;
    var special = builder.cm.options.specialChars, mustWrap = false;
    if (!special.test(text)) {
      builder.col += text.length;
      var content = document.createTextNode(text);
      builder.map.push(builder.pos, builder.pos + text.length, content);
      if (ie && ie_version < 9) mustWrap = true;
      builder.pos += text.length;
    } else {
      var content = document.createDocumentFragment(), pos = 0;
      while (true) {
        special.lastIndex = pos;
        var m = special.exec(text);
        var skipped = m ? m.index - pos : text.length - pos;
        if (skipped) {
          var txt = document.createTextNode(text.slice(pos, pos + skipped));
          if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
          else content.appendChild(txt);
          builder.map.push(builder.pos, builder.pos + skipped, txt);
          builder.col += skipped;
          builder.pos += skipped;
        }
        if (!m) break;
        pos += skipped + 1;
        if (m[0] == "\t") {
          var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
          var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
          txt.setAttribute("role", "presentation");
          builder.col += tabWidth;
        } else {
          var txt = builder.cm.options.specialCharPlaceholder(m[0]);
          if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
          else content.appendChild(txt);
          builder.col += 1;
        }
        builder.map.push(builder.pos, builder.pos + 1, txt);
        builder.pos++;
      }
    }
    if (style || startStyle || endStyle || mustWrap || css) {
      var fullStyle = style || "";
      if (startStyle) fullStyle += startStyle;
      if (endStyle) fullStyle += endStyle;
      var token = elt("span", [content], fullStyle, css);
      if (title) token.title = title;
      return builder.content.appendChild(token);
    }
    builder.content.appendChild(content);
  }
function buildToken ( builder , text , style , startStyle , endStyle , title , css ) { if ( ! text ) return ; var special = builder . cm . options . specialChars , mustWrap = false ; if ( ! special . test ( text ) ) { builder . col += text . length ; var content = document . createTextNode ( text ) ; builder . map . push ( builder . pos , builder . pos + text . length , content ) ; if ( ie && ie_version < 9 ) mustWrap = true ; builder . pos += text . length ; } else { var content = document . createDocumentFragment ( ) , pos = 0 ; while ( true ) { special . lastIndex = pos ; var m = special . exec ( text ) ; var skipped = m ? m . index - pos : text . length - pos ; if ( skipped ) { var txt = document . createTextNode ( text . slice ( pos , pos + skipped ) ) ; if ( ie && ie_version < 9 ) content . appendChild ( elt ( "span" , [ txt ] ) ) ; else content . appendChild ( txt ) ; builder . map . push ( builder . pos , builder . pos + skipped , txt ) ; builder . col += skipped ; builder . pos += skipped ; } if ( ! m ) break ; pos += skipped + 1 ; if ( m [ 0 ] == "\t" ) { var tabSize = builder . cm . options . tabSize , tabWidth = tabSize - builder . col % tabSize ; var txt = content . appendChild ( elt ( "span" , spaceStr ( tabWidth ) , "cm-tab" ) ) ; txt . setAttribute ( "role" , "presentation" ) ; builder . col += tabWidth ; } else { var txt = builder . cm . options . specialCharPlaceholder ( m [ 0 ] ) ; if ( ie && ie_version < 9 ) content . appendChild ( elt ( "span" , [ txt ] ) ) ; else content . appendChild ( txt ) ; builder . col += 1 ; } builder . map . push ( builder . pos , builder . pos + 1 , txt ) ; builder . pos ++ ; } } if ( style || startStyle || endStyle || mustWrap || css ) { var fullStyle = style || "" ; if ( startStyle ) fullStyle += startStyle ; if ( endStyle ) fullStyle += endStyle ; var token = elt ( "span" , [ content ] , fullStyle , css ) ; if ( title ) token . title = title ; return builder . content . appendChild ( token ) ; } builder . content . appendChild ( content ) ; }
Build up the DOM representation for a single token, and add it to the line map. Takes care to render special characters separately.
Build up the DOM representation for a single token and add it to the line map . Takes care to render special characters separately .