code: function( containerNode )
      {
          if( getSelectionCollapsed( containerNode ) )
              return null;
          if( window.getSelection )
          {
              var sel = window.getSelection();
              if( sel.rangeCount )
              {
                  var container = document.createElement('div'),
                      len = sel.rangeCount;
                  for( var i=0; i < len; ++i )
                  {
                      var contents = sel.getRangeAt(i).cloneContents();
                      container.appendChild(contents);
                  }
                  return container.innerHTML;
              }
          }
          else if( document.selection )
          {
              var sel = document.selection;
              if( sel.type == 'Text' )
              {
                  var range = sel.createRange();
                  return range.htmlText;
              }
          }
          return null;
      }
docs: http://stackoverflow.com/questions/4652734/return-html-from-a-user-selected-text/4652824#4652824