From f5cbcc4f56d37ef91b503ce91985252986a841e9 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 13 Dec 2013 17:39:12 +0000 Subject: [PATCH] Add useful HTML in toDomElements for refs and templates. For the benefit of pasting out of VE. Use data-ve-ignore where necessary to avoid the HTML being used on the way back in to VE. Change-Id: Iabe678c4246c1d1f51abb058b6e750811fdf9bea --- .../ve-mw/dm/nodes/ve.dm.MWReferenceNode.js | 4 +++ .../dm/nodes/ve.dm.MWTransclusionNode.js | 27 +++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js index da0b7bb0bb..7d6a3162f6 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWReferenceNode.js @@ -187,6 +187,10 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver } } else { el.setAttribute( 'data-mw', JSON.stringify( mwData ) ); + // HTML for the external clipboard, it will be ignored by the converter + $( el ).append( + $( '', doc ).text( this.getIndexLabel( dataElement, converter.internalList ) ) + ); } return [ el ]; diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js index 875642eff3..52b77257b7 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js @@ -89,7 +89,7 @@ ve.dm.MWTransclusionNode.static.toDataElement = function ( domElements, converte }; ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc, converter ) { - var el, + var els, currentDom, i, len, index = converter.getStore().indexOfHash( OO.getHash( [ this.getHashObject( dataElement ), undefined ] ) ), originalMw = dataElement.attributes.originalMw; @@ -105,20 +105,31 @@ ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc, con return ve.copyDomElements( dataElement.attributes.originalDomElements, doc ); } else { if ( dataElement.attributes.originalDomElements ) { - el = doc.createElement( dataElement.attributes.originalDomElements[0].nodeName ); + els = [ doc.createElement( dataElement.attributes.originalDomElements[0].nodeName ) ]; } else { - el = doc.createElement( 'span' ); + els = [ doc.createElement( 'span' ) ]; + // For the clipboard use the current DOM contents but mark is ignored + // for the converter + currentDom = converter.getStore().value( index ); + if ( currentDom ) { + currentDom = ve.copyDomElements( currentDom, doc ); + // i = 0 is the span + for ( i = 1, len = currentDom.length; i < len; i++ ) { + currentDom[i].setAttribute( 'data-ve-ignore', 'true' ); + els.push( currentDom[i] ); + } + } } // All we need to send back to Parsoid is the original transclusion marker, with a // reconstructed data-mw property. - el.setAttribute( 'typeof', 'mw:Transclusion' ); - el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) ); - // Mark the element as not having a generated contents with it in case it is + els[0].setAttribute( 'typeof', 'mw:Transclusion' ); + els[0].setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) ); + // Mark the element as not having valid generated contents with it in case it is // inserted into another editor (e.g. via paste). - el.setAttribute( 'data-ve-no-generated-contents', true ); + els[0].setAttribute( 'data-ve-no-generated-contents', true ); // TODO: Include last-known generated contents in the output for rich // paste into a non-VE editor - return [ el ]; + return els; } };