mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Add .static.storeHtmlAttributes
Defaults to true, but set to false, so we don't do redundant work for aliens. Change-Id: If35db3a67afd78124b4b2b46bb78ad60cbac46f5
This commit is contained in:
parent
b553cb9f21
commit
bbe3783d58
|
@ -31,6 +31,8 @@ ve.dm.AlienNode.static.name = 'alien';
|
|||
|
||||
ve.dm.AlienNode.static.matchTagNames = [];
|
||||
|
||||
ve.dm.AlienNode.static.storeHtmlAttributes = false;
|
||||
|
||||
ve.dm.AlienNode.static.toDataElement = function ( domElement, context ) {
|
||||
// We generate alienBlock elements for block tags and alienInline elements for
|
||||
// inline tags; unless we're in a content location, in which case we have no choice
|
||||
|
|
|
@ -171,7 +171,10 @@ ve.dm.Converter.prototype.getDataElementFromDomElement = function ( domElement,
|
|||
}
|
||||
dataElement = this.elements.toDataElement[domElementType]( domElement );
|
||||
domElementAttributes = domElement.attributes;
|
||||
if ( domElementAttributes.length ) {
|
||||
if (
|
||||
dataElement && ve.dm.nodeFactory.doesNodeStoreHtmlAttributes( dataElement.type ) &&
|
||||
domElementAttributes.length
|
||||
) {
|
||||
dataElementAttributes = dataElement.attributes = dataElement.attributes || {};
|
||||
// Include all attributes and prepend 'html/0/' to each attribute name
|
||||
for ( i = 0; i < domElementAttributes.length; i++ ) {
|
||||
|
|
|
@ -150,6 +150,20 @@ ve.dm.Node.static.toDomElement = function ( /*dataElement*/ ) {
|
|||
*/
|
||||
ve.dm.Node.static.isMeta = false;
|
||||
|
||||
/**
|
||||
* Whether HTML attributes should be preserved for this node type. If true, the HTML attributes
|
||||
* of the DOM elements will be stored as linear model attributes. The attribute names be
|
||||
* html/0/attrName, where attrName is the name of the attribute.
|
||||
*
|
||||
* This should generally be enabled, except for node types that store their entire HTML in an
|
||||
* attribute.
|
||||
*
|
||||
* @static
|
||||
* @property {boolean} static.storeHtmlAttributes
|
||||
* @inheritable
|
||||
*/
|
||||
ve.dm.Node.static.storeHtmlAttributes = true;
|
||||
|
||||
/**
|
||||
* Whether this node type has a wrapping element in the linear model. Most node types are wrapped,
|
||||
* only special node types are not wrapped.
|
||||
|
|
|
@ -186,6 +186,20 @@ ve.dm.NodeFactory.prototype.doesNodeHaveSignificantWhitespace = function ( type
|
|||
throw new Error( 'Unknown node type: ' + type );
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the node stores HTML attributes in the linear model.
|
||||
*
|
||||
* @method
|
||||
* @param {string} type Node type
|
||||
* @returns {[type]} The node stores HTML attributes
|
||||
*/
|
||||
ve.dm.NodeFactory.prototype.doesNodeStoreHtmlAttributes = function ( type ) {
|
||||
if ( type in this.registry ) {
|
||||
return this.registry[type].static.storeHtmlAttributes;
|
||||
}
|
||||
throw new Error( 'Unknown node type: ' + type );
|
||||
};
|
||||
|
||||
/* Initialization */
|
||||
|
||||
ve.dm.nodeFactory = new ve.dm.NodeFactory();
|
||||
|
|
Loading…
Reference in a new issue