mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Specify (but do not implement) the context parameter to toDataElement()
This allows the converter to provide the node handlers with context information, which hybrid nodes (such as alien and meta) need to decide which shape to take. Change-Id: I36860bee560a38ee39a149109be3706e39258edc
This commit is contained in:
parent
48bf0fbaab
commit
ac6c9b2418
|
@ -92,6 +92,22 @@ ve.dm.Node.static.matchFunction = null;
|
|||
* This function is only called if this node "won" the matching for the DOM element, so domElement
|
||||
* will match this node's matching rule.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* - if a non-content element is expected but a content element is returned:
|
||||
* - open a wrapper paragraph
|
||||
* - put the returned element in the wrapper
|
||||
* - if a content element is expected but a non-content element is returned:
|
||||
* - if we are in a wrapper paragraph:
|
||||
* - if we can close the wrapper:
|
||||
* - close the wrapper
|
||||
* - insert the returned element right after the end of the wrapper
|
||||
* - if we can't close the wrapper:
|
||||
* - alienate the element
|
||||
* - if we aren't in a wrapper paragraph:
|
||||
* - alienate the element
|
||||
*
|
||||
* The returned linear model element must have a type property set to a registered node name
|
||||
* (usually the node's .static.name, but that's not required). It may optionally have an attributes
|
||||
* property set to an object with key-value pairs. Any other properties are not allowed.
|
||||
|
@ -99,9 +115,15 @@ ve.dm.Node.static.matchFunction = null;
|
|||
* @static
|
||||
* @method
|
||||
* @param {HTMLElement} domElement DOM element to convert
|
||||
* @returns {Object} Linear model 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
|
||||
* @returns {Object|null} Linear model element, or null to alienate
|
||||
*/
|
||||
ve.dm.Node.static.toDataElement = function ( /*domElement*/ ) {
|
||||
ve.dm.Node.static.toDataElement = function ( /*domElement, context*/ ) {
|
||||
throw new Error( 've.dm.Node subclass must implement toDataElement' );
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue