jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 8856e2d..1150a94 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1872,7 +1872,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(),
@@ -1880,12 +1880,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
@@ -2011,7 +2011,7 @@
                        );
 
                        if ( this.pasteSpecial ) {
-                               sanitize( pasteData, true );
+                               sanitize( pasteData );
                        }
 
                        // Insert content
@@ -2025,7 +2025,7 @@
                        );
 
                        if ( this.pasteSpecial ) {
-                               sanitize( pasteData, true );
+                               sanitize( pasteData );
                        }
 
                        // Insert content
@@ -2129,10 +2129,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: merged
Gerrit-Change-Id: I62b6897050c4257ce23f3420627016bea306e245
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to