Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/267286
Change subject: Sanitization: Add option to perform per-node sanitization
......................................................................
Sanitization: Add option to perform per-node sanitization
And for ClassAttributeNodes, remove unrecognized CSS classes.
Change-Id: Ia3ce386b2a03bc227818b10423bca72c736c0656
---
M src/dm/lineardata/ve.dm.ElementLinearData.js
M src/dm/ve.dm.ClassAttributeNode.js
M src/dm/ve.dm.Node.js
M src/init/ve.init.Target.js
4 files changed, 31 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/86/267286/1
diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index ac5af94..91059bc 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -995,10 +995,11 @@
* @param {boolean} [rules.plainText] Remove all formatting for plain text
import
* @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
*/
ve.dm.ElementLinearData.prototype.sanitize = function ( rules,
keepEmptyContentBranches ) {
- var i, len, annotations, emptySet, setToRemove, type,
canContainContent, contentElement, isOpen,
+ var i, len, annotations, emptySet, setToRemove, type,
canContainContent, contentElement, isOpen, nodeClass,
allAnnotations = this.getAnnotationsFromRange( new ve.Range( 0,
this.getLength() ), true );
if ( rules.plainText ) {
@@ -1119,9 +1120,16 @@
this.setAnnotationsAtOffset( i, annotations );
}
}
- if ( this.isOpenElementData( i ) &&
rules.removeOriginalDomElements ) {
- // Remove originalDomElements from nodes
- delete this.getData( i ).originalDomElements;
+ if ( this.isOpenElementData( i ) ) {
+ if ( rules.nodeSanitization ) {
+ nodeClass = ve.dm.modelRegistry.lookup(
this.getType( i ) );
+ // Perform per-class sanitizations:
+ nodeClass.static.sanitize( this.getData( i ),
rules );
+ }
+ if ( rules.removeOriginalDomElements ) {
+ // Remove originalDomElements from nodes
+ delete this.getData( i ).originalDomElements;
+ }
}
}
};
diff --git a/src/dm/ve.dm.ClassAttributeNode.js
b/src/dm/ve.dm.ClassAttributeNode.js
index 63ca0db..9e52bfb 100644
--- a/src/dm/ve.dm.ClassAttributeNode.js
+++ b/src/dm/ve.dm.ClassAttributeNode.js
@@ -104,3 +104,12 @@
return null;
};
+
+/**
+ * @inheritdoc ve.dm.Node
+ */
+ve.dm.ClassAttributeNode.static.sanitize = function ( dataElement ) {
+ if ( dataElement.attributes ) {
+ delete dataElement.attributes.unrecognizedClasses;
+ }
+};
diff --git a/src/dm/ve.dm.Node.js b/src/dm/ve.dm.Node.js
index ca69fa1..d27a975 100644
--- a/src/dm/ve.dm.Node.js
+++ b/src/dm/ve.dm.Node.js
@@ -220,6 +220,14 @@
ve.dm.Node.static.defaultAttributes = {};
/**
+ * Sanitize the node's linear model data, typically if it was generated from
an external source (e.g. copied HTML)
+ *
+ * @param {Object} dataElement Linear model element, modified in place
+ */
+ve.dm.Node.static.sanitize = function () {
+};
+
+/**
* Remap the store indexes stored in a linear model data element.
*
* The default implementation is empty. Nodes should override this if they
store store indexes in
diff --git a/src/init/ve.init.Target.js b/src/init/ve.init.Target.js
index 46ef748..fde511e 100644
--- a/src/init/ve.init.Target.js
+++ b/src/init/ve.init.Target.js
@@ -177,7 +177,8 @@
'textStyle/span', 'textStyle/font',
// Nodes
'alienInline', 'alienBlock', 'comment'
- ]
+ ],
+ nodeSanitization: true
},
all: null
};
--
To view, visit https://gerrit.wikimedia.org/r/267286
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3ce386b2a03bc227818b10423bca72c736c0656
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits