Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58643
Change subject: Pass the converter object to the node handler in toDataElement()
......................................................................
Pass the converter object to the node handler in toDataElement()
This will allow node handlers to recursively invoke getDataFromDomRecursion()
Change-Id: I12cd4b31614a549bfbe8fbdc7d0607ece32aa98a
---
M modules/ve/dm/nodes/ve.dm.AlienNode.js
M modules/ve/dm/ve.dm.Converter.js
M modules/ve/dm/ve.dm.Model.js
3 files changed, 17 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/43/58643/1
diff --git a/modules/ve/dm/nodes/ve.dm.AlienNode.js
b/modules/ve/dm/nodes/ve.dm.AlienNode.js
index 0d60f1b..2e6f077 100644
--- a/modules/ve/dm/nodes/ve.dm.AlienNode.js
+++ b/modules/ve/dm/nodes/ve.dm.AlienNode.js
@@ -34,7 +34,7 @@
ve.dm.AlienNode.static.storeHtmlAttributes = false;
-ve.dm.AlienNode.static.toDataElement = function ( domElements, context ) {
+ve.dm.AlienNode.static.toDataElement = function ( domElements, converter ) {
var i, isInline, allTagsInline, type, html;
// Check whether all elements are inline elements
allTagsInline = true;
@@ -50,9 +50,9 @@
// but to generate an alienInline element.
isInline =
// Force inline in content locations (but not wrappers)
- ( context.expectingContent && !context.inWrapper ) ||
+ ( converter.isExpectingContent() && !converter.isInWrapper() )
||
// Also force inline in wrappers that we can't close
- ( context.inWrapper && !context.canCloseWrapper ) ||
+ ( converter.isInWrapper() && !converter.canCloseWrapper() ) ||
// Look at the tag names otherwise
allTagsInline;
type = isInline ? 'alienInline' : 'alienBlock';
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index b8d28e5..583865f 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -222,12 +222,11 @@
* Create a data element from a DOM element.
* @param {ve.dm.Model} modelClass Model class to use for conversion
* @param {HTMLElement[]} domElements DOM elements to convert
- * @param {Object} context Converter context to pass to toDataElement() (will
be cloned)
* @returns {Object} Data element
*/
-ve.dm.Converter.prototype.createDataElement = function ( modelClass,
domElements, context ) {
+ve.dm.Converter.prototype.createDataElement = function ( modelClass,
domElements ) {
var i, j, dataElement, dataElementAttributes, domElementAttributes,
domElementAttribute;
- dataElement = modelClass.static.toDataElement( domElements,
ve.copyObject( context ) );
+ dataElement = modelClass.static.toDataElement( domElements, this );
if ( modelClass.static.storeHtmlAttributes && dataElement ) {
for ( i = 0; i < domElements.length; i++ ) {
domElementAttributes = domElements[i].attributes;
@@ -404,7 +403,7 @@
modelName = this.modelRegistry.matchElement(
childDomElement );
modelClass = this.modelRegistry.lookup(
modelName ) || ve.dm.AlienNode;
if ( modelClass.prototype instanceof
ve.dm.Annotation ) {
- annotationData =
this.createDataElement( modelClass, [ childDomElement ], context );
+ annotationData =
this.createDataElement( modelClass, [ childDomElement ] );
}
if ( modelClass.prototype instanceof
ve.dm.Annotation && annotationData ) {
annotation =
this.annotationFactory.create( modelName, annotationData );
@@ -424,7 +423,7 @@
aboutGroup = getAboutGroup(
childDomElement );
childDomElements =
modelClass.static.enableAboutGrouping ?
aboutGroup : [ childDomElement
];
- childDataElement =
this.createDataElement( modelClass, childDomElements, context );
+ childDataElement =
this.createDataElement( modelClass, childDomElements );
if ( modelClass.prototype instanceof
ve.dm.MetaItem ) {
// No additional processing
needed
@@ -450,7 +449,7 @@
modelClass =
ve.dm.AlienNode;
childDomElements =
modelClass.static.enableAboutGrouping ?
aboutGroup : [
childDomElement ];
- childDataElement =
this.createDataElement( modelClass, childDomElements, context );
+ childDataElement =
this.createDataElement( modelClass, childDomElements );
childIsContent =
this.nodeFactory.isNodeContent( childDataElement.type );
}
}
diff --git a/modules/ve/dm/ve.dm.Model.js b/modules/ve/dm/ve.dm.Model.js
index 729ad60..9990b59 100644
--- a/modules/ve/dm/ve.dm.Model.js
+++ b/modules/ve/dm/ve.dm.Model.js
@@ -74,6 +74,13 @@
* If there are multiple nodes, the nodes are all adjacent siblings in the
same about group
* (i.e. they are grouped together because they have the same value for the
about attribute).
*
+ * The converter has some state variables that can be obtained by this
function:
+ * - if converter.isExpectingContent() returns true, the converter expects a
content element
+ * - if converter.isInWrapper() returns true, the returned element will be put
in a wrapper
+ * paragraph generated by the converter (this is only relevant if
isExpectingContent() is true)
+ * - converter.canCloseWrapper() returns true if the current wrapper paragraph
can be closed,
+ * and false if it can't be closed or if there is no active wrapper
+ *
* This function is allowed to return a content element when context indicates
that a non-content
* element is expected or vice versa. If that happens, the converter deals
with it in the following way:
*
@@ -103,15 +110,10 @@
* @inheritable
* @method
* @param {HTMLElement[]} domElements DOM elements to convert. Usually only
one element
- * @param {Object} context Object describing the current state of the converter
- * @param {boolean} context.expectingContent Whether this function is expected
to return a content element
- * @param {boolean} context.inWrapper Whether this element is in a wrapper
paragraph generated by the converter;
- * can only be true if context.expectingContent is also true
- * @param {boolean} context.canCloseWrapper Whether the current wrapper
paragraph can be closed;
- * can only be true if context.inWrapper is also true
+ * @param {ve.dm.Converter} converter Converter object
* @returns {Object|null} Linear model element, or null to alienate
*/
-ve.dm.Model.static.toDataElement = function ( /*domElements, context*/ ) {
+ve.dm.Model.static.toDataElement = function ( /*domElements, converter*/ ) {
throw new Error( 've.dm.Model subclass must implement toDataElement' );
};
--
To view, visit https://gerrit.wikimedia.org/r/58643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I12cd4b31614a549bfbe8fbdc7d0607ece32aa98a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits