Index: /CKEditor/branches/prototype/_source/core/config.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/config.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/core/config.js	(revision 2639)
@@ -159,5 +159,5 @@
 	 * config.plugins = 'elementspath,toolbar,wysiwygarea';
 	 */
-	plugins : 'basicstyles,button,dialog,elementspath,htmldataprocessor,keystrokes,smiley,sourcearea,tab,toolbar,wysiwygarea',
+	plugins : 'basicstyles,button,dialog,elementspath,htmldataprocessor,keystrokes,removeformat,smiley,sourcearea,tab,toolbar,wysiwygarea',
 
 	/**
Index: /CKEditor/branches/prototype/_source/core/dom/documentFragment.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/dom/documentFragment.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/core/dom/documentFragment.js	(revision 2639)
@@ -41,4 +41,19 @@
 			else
 				targetElement.$.appendChild( this.$ );
+		},
+
+		insertAfterNode : function( node )
+		{
+			var $ = this.$;
+			var $node = node.$;
+			var $parent = $node.parentNode;
+
+			if ( CKEDITOR.env.ie )
+			{
+				for ( var child ; child = $.lastChild ; )
+					$parent.insertBefore( $.removeChild( child ), $node.nextSibling );
+			}
+			else
+				$parent.insertBefore( $, $node.nextSibling );
 		}
 	};
Index: /CKEditor/branches/prototype/_source/core/dom/element.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/dom/element.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/core/dom/element.js	(revision 2639)
@@ -201,4 +201,40 @@
 		},
 
+		/**
+		 * Breaks one of the ancestor element in the element position, moving
+		 * this element between the broken parts.
+		 * @param {CKEDITOR.dom.element} parent The anscestor element to get broken.
+		 * @example
+		 * // Before breaking:
+		 * //     <b>This <i>is some<span /> sample</i> test text</b>
+		 * // If "element" is <span /> and "parent" is <i>:
+		 * //     <b>This <i>is some</i><span /><i> sample</i> test text</b>
+		 * element.breakParent( parent );
+		 * @example
+		 * // Before breaking:
+		 * //     <b>This <i>is some<span /> sample</i> test text</b>
+		 * // If "element" is <span /> and "parent" is <b>:
+		 * //     <b>This <i>is some</i></b><span /><b><i> sample</i> test text</b>
+		 * element.breakParent( parent );
+		 */
+		breakParent : function( parent )
+		{
+			var range = new CKEDITOR.dom.range( this.getDocument() );
+
+			// We'll be extracting part of this element, so let's use our
+			// range to get the correct piece.
+			range.setStartAfter( this );
+			range.setEndAfter( parent );
+
+			// Extract it.
+			var docFrag = range.extractContents();
+
+			// Move the element outside the broken element.
+			range.insertNode( this.remove() );
+
+			// Re-insert the extracted piece after the element.
+			docFrag.insertAfterNode( this );
+		},
+
 		contains :
 			CKEDITOR.env.ie || CKEDITOR.env.webkit ?
@@ -326,4 +362,9 @@
 				return standard;
 		})(),
+
+		getChildren : function()
+		{
+			return new CKEDITOR.dom.nodeList( this.$.childNodes );
+		},
 
 		/**
@@ -596,4 +637,6 @@
 							case '_cke_expando' :
 								continue;
+
+							/*jsl:fallthru*/
 
 							default :
@@ -752,4 +795,10 @@
 				return standard;
 		})(),
+
+		removeAttributes : function ( attributes )
+		{
+			for ( var i = 0 ; i < attributes.length ; i++ )
+				this.removeAttribute( attributes[ i ] );
+		},
 
 		/**
Index: /CKEditor/branches/prototype/_source/core/dom/elementpath.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/dom/elementpath.js	(revision 2639)
+++ /CKEditor/branches/prototype/_source/core/dom/elementpath.js	(revision 2639)
@@ -0,0 +1,93 @@
+﻿/*
+ * CKEditor - The text editor for Internet - http://ckeditor.com
+ * Copyright (C) 2003-2008 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ */
+
+(function()
+{
+	// Elements that may be considered the "Block boundary" in an element path.
+	var pathBlockElements = { address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,de:1 };
+
+	// Elements that may be considered the "Block limit" in an element path.
+	var pathBlockLimitElements = { body:1,div:1,td:1,th:1,caption:1,form:1 };
+
+	// Check if an element contains any block element.
+	var checkHasBlock = function( element )
+	{
+		var childNodes = element.getChildren();
+
+		for ( var i = 0, count = childNodes.count() ; i < count ; i++ )
+		{
+			var child = childNodes.getItem( i );
+
+			if ( child.type == CKEDITOR.NODE_ELEMENT && CKEDITOR.dtd.$block[ child.getName() ] )
+				return true;
+		}
+
+		return false;
+	};
+
+	CKEDITOR.dom.elementPath = function( lastNode )
+	{
+		var block = null;
+		var blockLimit = null;
+		var elements = [];
+
+		var e = lastNode;
+
+		while ( e )
+		{
+			if ( e.type == CKEDITOR.NODE_ELEMENT )
+			{
+				if ( !this.lastElement )
+					this.lastElement = e;
+
+				var elementName = e.getName();
+				if ( CKEDITOR.env.ie && e.$.scopeName != 'HTML' )
+					elementName = e.$.scopeName.toLowerCase() + ':' + elementName;
+
+				if ( !blockLimit )
+				{
+					if ( !block && pathBlockElements[ elementName ] )
+						block = e;
+
+					if ( pathBlockLimitElements[ elementName ] )
+					{
+						// DIV is considered the Block, if no block is available (#525)
+						// and if it doesn't contain other blocks.
+						if ( !block && elementName == 'div' && !checkHasBlock( e ) )
+							block = e;
+						else
+							blockLimit = e;
+					}
+				}
+
+				elements.push( e );
+
+				if ( elementName == 'body' )
+					break;
+			}
+			e = e.getParent();
+		}
+
+		this.block = block;
+		this.blockLimit = blockLimit;
+		this.elements = elements;
+	};
+})();
Index: /CKEditor/branches/prototype/_source/core/dom/node.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/dom/node.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/core/dom/node.js	(revision 2639)
@@ -241,5 +241,5 @@
 		},
 
-		getNextSourceNode : function( startFromSibling )
+		getNextSourceNode : function( startFromSibling, nodeType )
 		{
 			var $ = this.$;
@@ -253,4 +253,10 @@
 			while ( !node && ( parent = ( parent || $ ).parentNode ) )
 				node = parent.nextSibling;
+
+			if ( !node )
+				return null;
+
+			if ( nodeType && nodeType != node.nodeType )
+				return arguments.callee.call( { $ : node }, false, nodeType );
 
 			return new CKEDITOR.dom.node( node );
Index: /CKEditor/branches/prototype/_source/core/loader.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/loader.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/core/loader.js	(revision 2639)
@@ -40,5 +40,5 @@
 		var scripts =
 		{
-			'core/_bootstrap'		: [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we wnat to force loading to at the end to avoid dependence recursion */ 'core/dom/text', 'core/dom/range' ],
+			'core/_bootstrap'		: [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we want to force loading at the end to avoid dependence recursion */ 'core/dom/elementpath', 'core/dom/text', 'core/dom/range' ],
 			'core/ajax'				: [ 'core/xml' ],
 			'core/ckeditor'			: [ 'core/ajax', 'core/ckeditor_basic', 'core/dom', 'core/dtd', 'core/dom/document', 'core/dom/element', 'core/editor', 'core/event', 'core/htmlparser', 'core/htmlparser/element', 'core/htmlparser/fragment', 'core/tools' ],
@@ -50,4 +50,5 @@
 			'core/dom/documentfragment'	: [ 'core/dom/element' ],
 			'core/dom/element'		: [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ],
+			'core/dom/elementpath'	: [ 'core/dom/element' ],
 			'core/dom/event'		: [],
 			'core/dom/node'			: [ 'core/dom/domobject', 'core/tools' ],
Index: /CKEditor/branches/prototype/_source/lang/en.js
===================================================================
--- /CKEditor/branches/prototype/_source/lang/en.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/lang/en.js	(revision 2639)
@@ -45,9 +45,10 @@
 
 	// Toolbar buttons.
-	source		: 'Source',
-	underline	: 'Underline',
-	bold		: 'Bold',
-	italic		: 'Italic',
-	selectAll	: 'Select all',
+	source			: 'Source',
+	underline		: 'Underline',
+	bold			: 'Bold',
+	italic			: 'Italic',
+	selectAll		: 'Select All',
+	removeFormat	: 'Remove Format',
 
 	elementsPath :
Index: /CKEditor/branches/prototype/_source/plugins/removeformat/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/removeformat/plugin.js	(revision 2639)
+++ /CKEditor/branches/prototype/_source/plugins/removeformat/plugin.js	(revision 2639)
@@ -0,0 +1,131 @@
+﻿/*
+ * CKEditor - The text editor for Internet - http://ckeditor.com
+ * Copyright (C) 2003-2008 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ */
+
+CKEDITOR.plugins.add( 'removeformat',
+{
+	requires : [ 'selection' ],
+
+	init : function( editor, pluginPath )
+	{
+		editor.addCommand( 'removeFormat', CKEDITOR.plugins.removeformat.commands.removeformat );
+		editor.ui.addButton( 'RemoveFormat',
+			{
+				label : editor.lang.removeFormat,
+				command : 'removeFormat'
+			});
+	}
+});
+
+CKEDITOR.plugins.removeformat =
+{
+	commands :
+	{
+		removeformat :
+		{
+			exec : function( editor )
+			{
+				var tagsRegex = editor._.removeFormatRegex ||
+					( editor._.removeFormatRegex = new RegExp( '^(?:' + editor.config.removeFormatTags.replace( /,/g,'|' ) + ')$', 'i' ) );
+
+				var removeAttributes = editor._.removeAttributes ||
+					( editor._.removeAttributes = editor.config.removeFormatAttributes.split( ',' ) );
+
+				var ranges = editor.getSelection().getRanges();
+
+				for ( var i = 0, range ; range = ranges[ i ] ; i++ )
+				{
+					if ( range.collapsed )
+						continue;
+
+					range.enlarge( CKEDITOR.ENLARGE_ELEMENT );
+
+					// Bookmark the range so we can re-select it after processing.
+					var bookmark = range.createBookmark();
+
+					// The style will be applied within the bookmark boundaries.
+					var startNode	= bookmark.startNode;
+					var endNode		= bookmark.endNode;
+
+					// We need to check the selection boundaries (bookmark spans) to break
+					// the code in a way that we can properly remove partially selected nodes.
+					// For example, removing a <b> style from
+					//		<b>This is [some text</b> to show <b>the] problem</b>
+					// ... where [ and ] represent the selection, must result:
+					//		<b>This is </b>[some text to show the]<b> problem</b>
+					// The strategy is simple, we just break the partial nodes before the
+					// removal logic, having something that could be represented this way:
+					//		<b>This is </b>[<b>some text</b> to show <b>the</b>]<b> problem</b>
+
+					var breakParent = function( node )
+					{
+						// Let's start checking the start boundary.
+						var path = new CKEDITOR.dom.elementPath( node );
+						var pathElements = path.elements;
+
+						for ( var i = 1, pathElement ; pathElement = pathElements[ i ] ; i++ )
+						{
+							if ( pathElement.equals( path.block ) || pathElement.equals( path.blockLimit ) )
+								break;
+
+							// If this element can be removed (even partially).
+							if ( tagsRegex.test( pathElement.getName() ) )
+								node.breakParent( pathElement );
+						}
+					};
+
+					breakParent( startNode );
+					breakParent( endNode );
+
+					// Navigate through all nodes between the bookmarks.
+					var currentNode = startNode.getNextSourceNode( true, CKEDITOR.NODE_ELEMENT );
+
+					while ( currentNode )
+					{
+						// If we have reached the end of the selection, stop looping.
+						if ( currentNode.equals( endNode ) )
+							break;
+
+						// Cache the next node to be processed. Do it now, because
+						// currentNode may be removed.
+						var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT );
+
+						// Remove elements nodes that match with this style rules.
+						if ( tagsRegex.test( currentNode.getName() ) )
+							currentNode.remove( true );
+						else
+							currentNode.removeAttributes( removeAttributes );
+
+						currentNode = nextNode;
+					}
+
+					range.moveToBookmark( bookmark );
+				}
+
+				editor.getSelection().selectRanges( ranges );
+			}
+		}
+	}
+};
+
+// Only inline elements are valid.
+CKEDITOR.config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var';
+
+CKEDITOR.config.removeFormatAttributes = 'class,style,lang,width,height,align,hspace,valign';
Index: /CKEditor/branches/prototype/_source/plugins/toolbar/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/toolbar/plugin.js	(revision 2638)
+++ /CKEditor/branches/prototype/_source/plugins/toolbar/plugin.js	(revision 2639)
@@ -222,4 +222,4 @@
 CKEDITOR.config.toolbar =
 [
-	[ 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'SelectAll', '-', 'Smiley' ]
+	[ 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'SelectAll', 'RemoveFormat', '-', 'Smiley' ]
 ];
Index: /CKEditor/branches/prototype/_source/skins/default/toolbar.css
===================================================================
--- /CKEditor/branches/prototype/_source/skins/default/toolbar.css	(revision 2638)
+++ /CKEditor/branches/prototype/_source/skins/default/toolbar.css	(revision 2639)
@@ -137,4 +137,9 @@
 }
 
+.cke_skin_default a.cke_button_removeFormat .cke_icon
+{
+	background-position: 0 -288px;
+}
+
 .cke_skin_default a.cke_button_bold .cke_icon
 {
