code: function doInsertHeading(level){
    var rep = this.rep,
      documentAttributeManager = this.documentAttributeManager;
    if (!(rep.selStart && rep.selEnd) || (level >= 0 && tags[level] === undefined))
    {
      return;
    }
    
    var firstLine, lastLine;
    
    firstLine = rep.selStart[0];
    lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0));
    _(_.range(firstLine, lastLine + 1)).each(function(i){
      if(level >= 0){
        documentAttributeManager.setAttributeOnLine(i, 'heading', tags[level]);
      }else{
        documentAttributeManager.removeAttributeOnLine(i, 'heading');
      }
    });
  }
docs: Find out which lines are selected and assign them the heading attribute. Passing a level >= 0 will set a heading on the selected lines, level < 0 will remove it