Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/302256
Change subject: Make keepEmptyContentBranches an option of #sanitize and simplify usage ...................................................................... Make keepEmptyContentBranches an option of #sanitize and simplify usage Change-Id: I62b6897050c4257ce23f3420627016bea306e245 --- M src/ce/ve.ce.Surface.js M src/dm/lineardata/ve.dm.ElementLinearData.js M src/dm/ve.dm.Document.js 3 files changed, 12 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/56/302256/1 diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js index dca130a..7814d7a 100644 --- a/src/ce/ve.ce.Surface.js +++ b/src/ce/ve.ce.Surface.js @@ -1870,7 +1870,7 @@ tableAction, items = [], importantElement = '[id],[typeof],[rel]', - importRules = !this.pasteSpecial ? this.getSurface().getImportRules() : { all: { plainText: true } }, + importRules = !this.pasteSpecial ? this.getSurface().getImportRules() : { all: { plainText: true, keepEmptyContentBranches: true } }, beforePasteData = this.beforePasteData || {}, surfaceModel = this.getModel(), fragment = surfaceModel.getFragment(), @@ -1878,12 +1878,12 @@ documentModel = surfaceModel.getDocument(), view = this; - function sanitize( linearData, keepEmptyContentBranches ) { + function sanitize( linearData ) { // If the clipboardKey isn't set (paste from non-VE instance) use external import rules if ( !clipboardKey ) { - linearData.sanitize( importRules.external || {}, keepEmptyContentBranches ); + linearData.sanitize( importRules.external || {} ); } - linearData.sanitize( importRules.all || {}, keepEmptyContentBranches ); + linearData.sanitize( importRules.all || {} ); } // If the selection doesn't collapse after paste then nothing was inserted @@ -2009,7 +2009,7 @@ ); if ( this.pasteSpecial ) { - sanitize( pasteData, true ); + sanitize( pasteData ); } // Insert content @@ -2023,7 +2023,7 @@ ); if ( this.pasteSpecial ) { - sanitize( pasteData, true ); + sanitize( pasteData ); } // Insert content @@ -2127,10 +2127,8 @@ pastedDocumentModel.getStore(), ve.copy( beforePasteData.context ) ); - if ( this.pasteSpecial ) { - // The context may have been sanitized, so sanitize here as well for comparison - sanitize( context, true ); - } + // Sanitize context to match data + sanitize( context ); // Remove matching context from the left left = 0; diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js b/src/dm/lineardata/ve.dm.ElementLinearData.js index d687070..3d3cce2 100644 --- a/src/dm/lineardata/ve.dm.ElementLinearData.js +++ b/src/dm/lineardata/ve.dm.ElementLinearData.js @@ -1021,9 +1021,9 @@ * @param {boolean} [rules.allowBreaks] Allow <br> line breaks, otherwise the node will be split * @param {boolean} [rules.preserveHtmlWhitespace] Preserve non-semantic HTML whitespace * @param {boolean} [rules.nodeSanitization] Apply per-type node sanitizations via ve.dm.Node#sanitize - * @param {boolean} [keepEmptyContentBranches=false] Preserve empty content branch nodes + * @param {boolean} [rules.keepEmptyContentBranches] Preserve empty content branch nodes */ -ve.dm.ElementLinearData.prototype.sanitize = function ( rules, keepEmptyContentBranches ) { +ve.dm.ElementLinearData.prototype.sanitize = function ( rules ) { var i, len, annotations, emptySet, setToRemove, type, canContainContent, contentElement, isOpen, nodeClass, ann, oldHash, store = this.getStore(), @@ -1098,7 +1098,7 @@ // If a node is empty but can contain content, then just remove it if ( - !keepEmptyContentBranches && + !rules.keepEmptyContentBranches && i > 0 && !isOpen && this.isOpenElementData( i - 1 ) && canContainContent ) { diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js index 0e7201f..bc6b3a8 100644 --- a/src/dm/ve.dm.Document.js +++ b/src/dm/ve.dm.Document.js @@ -1432,9 +1432,7 @@ if ( importRules ) { data.sanitize( importRules.external || {} ); - if ( importRules.all ) { - data.sanitize( importRules.all ); - } + data.sanitize( importRules.all || {} ); } data.remapInternalListKeys( this.getInternalList() ); -- To view, visit https://gerrit.wikimedia.org/r/302256 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62b6897050c4257ce23f3420627016bea306e245 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits