diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js index bbec93dab1..0800be7312 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWTransclusionNode.js @@ -207,6 +207,15 @@ ve.ce.MWTransclusionNode.prototype.getRenderedDomElements = function () { return elements; }; +/** + * @inheritdoc + */ +ve.ce.MWTransclusionNode.prototype.filterRenderedDomElements = function ( domElements ) { + // We want to remove all styles and links which aren't from TemplateStyles. + var selector = 'style:not([data-mw-deduplicate^="TemplateStyles:"]), link:not([rel="mw-deduplicated-inline-style"][href^="mw-data:TemplateStyles:"])'; + return $( domElements ).find( selector ).addBack( selector ).remove().end().end().toArray(); +}; + /** * Handle an unsuccessful response from the parser for the wikitext fragment. * diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index 097dca06a0..02dad3ad32 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -670,7 +670,9 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) $( 'html' ).removeClass( 've-deactivating' ); // Move original content back out of the target - target.$element.parent().append( target.$originalContent.children() ); + target.$element.parent().append( target.$originalContent.children() ) + // Restore TemplateStyles within it + .find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', false ); $( '.ve-init-mw-desktopArticleTarget-uneditableContent' ) .removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' ); @@ -1212,6 +1214,10 @@ ve.init.mw.DesktopArticleTarget.prototype.transformPage = function () { // Move all native content inside the target // Exclude notification area to work around T143837 this.$originalContent.append( this.$element.siblings().not( '.mw-notification-area' ) ); + + // Disable TemplateStyles in originalContent + this.$originalContent.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', true ); + this.$originalCategories = $( '#catlinks' ).clone( true ); // Mark every non-direct ancestor between editableContent and the container as uneditable