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:
Catrope 2013-02-15 17:42:25 -08:00
parent b553cb9f21
commit bbe3783d58
4 changed files with 34 additions and 1 deletions

View file

@ -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

View file

@ -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++ ) {

View file

@ -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.

View file

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