From 3068c496c97179419c41bd12b2c5552c8b9db4b4 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 15 Nov 2011 21:46:47 +1100 Subject: [PATCH] Allow contents of unknown tags in. Clean functions were removing contents of any unknown tag. This was, it turned out, a bit too strict. --- source/Editor.js | 49 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/source/Editor.js b/source/Editor.js index 9e7e8af..a287923 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -641,9 +641,11 @@ } if ( mutates ) { + setSelection( range ); + // Path may have changed updatePath( 0, true ); - + // We're not still in an undo state docWasChanged(); } @@ -898,6 +900,15 @@ parent.replaceChild( el, node ); el.appendChild( node.empty() ); return el; + }, + TT: function ( node, parent ) { + var el = createElement( 'SPAN', { + 'class': 'font', + style: 'font-family:menlo,consolas,"courier new",monospace' + }); + parent.replaceChild( el, node ); + el.appendChild( node.empty() ); + return el; } }; @@ -910,29 +921,36 @@ */ var cleanTree = function ( node, allowStyles ) { var children = node.childNodes, - i, l, child, nodeName, nodeType, rewriter, parent; + i, l, child, nodeName, nodeType, rewriter, childLength; for ( i = 0, l = children.length; i < l; i += 1 ) { child = children[i]; nodeName = child.nodeName; nodeType = child.nodeType; rewriter = stylesRewriters[ nodeName ]; - if ( rewriter ) { - child = rewriter( child, node ); - } else if ( - ( !allowedBlock.test( nodeName ) && !child.isInline() ) || - ( nodeType === TEXT_NODE && !( /\S/.test( child.data ) ) ) ) { - node.removeChild( child ); - i -= 1; - l -= 1; - continue; - } if ( nodeType === ELEMENT_NODE ) { + childLength = child.childNodes.length; + if ( rewriter ) { + child = rewriter( child, node ); + } else if ( !allowedBlock.test( nodeName ) && + !child.isInline() ) { + i -= 1; + l += childLength - 1; + node.replaceChild( child.empty(), child ); + continue; + } if ( !allowStyles && child.style.cssText ) { child.removeAttribute( 'style' ); } - if ( child.childNodes.length ) { + if ( childLength ) { cleanTree( child, allowStyles ); } + } else { + if ( ( nodeType !== TEXT_NODE ) || + !( /\S/.test( child.data ) ) ) { + node.removeChild( child ); + i -= 1; + l -= 1; + } } } return node; @@ -1575,4 +1593,9 @@ body.setAttribute( 'contenteditable', 'true' ); win.editor.setHTML( '' ); + if ( win.onEditorLoad ) { + win.onEditorLoad( win.editor ); + delete win.onEditorLoad; + } + }( document ) ); \ No newline at end of file