Merge "Correctly tag clipboard DM from MWTransclusionNodes"

This commit is contained in:
jenkins-bot 2015-02-16 18:27:01 +00:00 committed by Gerrit Code Review
commit 387bc2d794
2 changed files with 20 additions and 21 deletions

View file

@ -111,29 +111,19 @@ ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc, con
)
) {
// The object in the store is also used for CE rendering so return a copy
return ve.copyDomElements( dataElement.attributes.originalDomElements, doc );
els = ve.copyDomElements( dataElement.attributes.originalDomElements, doc );
} else {
if ( dataElement.attributes.originalDomElements ) {
els = [ doc.createElement( dataElement.attributes.originalDomElements[0].nodeName ) ];
} else {
els = [ doc.createElement( 'span' ) ];
if ( converter.isForClipboard() ) {
// For the clipboard use the current DOM contents but mark as ignored
// for the converter
// For the clipboard use the current DOM contents so the user has something
// meaningful to paste into external applications
currentDom = converter.getStore().value( index );
if ( currentDom ) {
currentDom = ve.copyDomElements( currentDom, doc );
// i = 0 is the data-mw span
for ( i = 1, len = currentDom.length; i < len; i++ ) {
// Wrap plain text nodes so we can give them an attribute
if ( currentDom[i].nodeType === Node.TEXT_NODE ) {
wrapper = doc.createElement( 'span' );
wrapper.appendChild( currentDom[i] );
currentDom[i] = wrapper;
}
currentDom[i].setAttribute( 'data-ve-ignore', 'true' );
els.push( currentDom[i] );
}
// Ignore currentDom[0] as that is the data-mw span we are recreating
els = els.concat( ve.copyDomElements( currentDom.slice( 1 ), doc ) );
}
}
}
@ -141,13 +131,24 @@ ve.dm.MWTransclusionNode.static.toDomElements = function ( dataElement, doc, con
// reconstructed data-mw property.
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
}
if ( converter.isForClipboard() ) {
// Mark the data-mw element as not having valid generated contents with it in case it is
// inserted into another editor (e.g. via paste).
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 els;
// ... and mark all but the first child as ignorable
for ( i = 1, len = els.length; i < len; i++ ) {
// Wrap plain text nodes so we can give them an attribute
if ( els[i].nodeType === Node.TEXT_NODE ) {
wrapper = doc.createElement( 'span' );
wrapper.appendChild( els[i] );
els[i] = wrapper;
}
els[i].setAttribute( 'data-ve-ignore', 'true' );
}
}
return els;
};
/**

View file

@ -25,7 +25,6 @@ ve.dm.mwExample.MWTransclusion = {
blockOpenModified:
'<div about="#mwt1" typeof="mw:Transclusion"' +
' data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Test&quot;,&quot;href&quot;:&quot;./Template:Test&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;Hello, globe!&quot;}},&quot;i&quot;:0}}]}"' +
' data-ve-no-generated-contents="true"' +
'>' +
'</div>',
blockContent: '<p about="#mwt1" data-parsoid="{}">Hello, world!</p>',
@ -36,7 +35,6 @@ ve.dm.mwExample.MWTransclusion = {
inlineOpenModified:
'<span about="#mwt1" typeof="mw:Transclusion"' +
' data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;Inline&quot;,&quot;href&quot;:&quot;./Template:Inline&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;5,678&quot;}},&quot;i&quot;:0}}]}"' +
' data-ve-no-generated-contents="true"' +
'>',
inlineContent: '$1,234.00',
inlineClose: '</span>',