diff --git a/core/modules/widgets/element.js b/core/modules/widgets/element.js index b3a970959..8253b70e1 100755 --- a/core/modules/widgets/element.js +++ b/core/modules/widgets/element.js @@ -25,7 +25,6 @@ Render this widget into the DOM */ ElementWidget.prototype.render = function(parent,nextSibling) { this.parentDomNode = parent; - this.computeAttributes(); // Neuter blacklisted elements this.tag = this.parseTreeNode.tag; if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) { @@ -42,15 +41,8 @@ ElementWidget.prototype.render = function(parent,nextSibling) { headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6); this.tag = "h" + headingLevel; } - // Check for element mapping - var mappedTag = this.getVariable("tv-map-" + this.tag); - if(mappedTag) { - this.tag = mappedTag.trim(); - var mappedClass = this.getVariable("tv-map-" + this.tag + "-class"); - if(mappedClass) { - this.setAttribute("class",mappedClass.trim() + (this.getAttribute("class") ? " " + this.getAttribute("class") : "")); - } - } + // Compute the attributes, mapping the element tag if needed + this.computeAttributes(); // Select the namespace for the tag var XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml", tagNamespaces = { @@ -108,4 +100,25 @@ ElementWidget.prototype.refresh = function(changedTiddlers) { return this.refreshChildren(changedTiddlers) || hasChangedAttributes; }; +/* +Override the base computeAttributes method +*/ +ElementWidget.prototype.computeAttributes = function() { + // Call the base class to compute the initial values of the attributes + var changedAttributes = Widget.prototype.computeAttributes.call(this); + // Check for element mapping + var mappedTag = this.getVariable("tv-map-" + this.tag), + mappedClass = this.getVariable("tv-map-" + this.tag + "-class"); + if(mappedTag) { + this.tag = mappedTag.trim(); + // Add an attribute to indicate the original tag + this.attributes["data-element-mapping-from"] = this.parseTreeNode.tag; + // Check for a mapped class + if(mappedClass) { + this.attributes["class"] = mappedClass.trim() + (this.attributes["class"] ? " " + this.attributes["class"] : ""); + } + } + return changedAttributes; +}; + exports.element = ElementWidget; diff --git a/editions/test/tiddlers/tests/data/element-mapping/Basic.tid b/editions/test/tiddlers/tests/data/element-mapping/Basic.tid index 008e0204a..2b5298ce8 100644 --- a/editions/test/tiddlers/tests/data/element-mapping/Basic.tid +++ b/editions/test/tiddlers/tests/data/element-mapping/Basic.tid @@ -16,4 +16,4 @@ This is a paragraph + title: ExpectedResult -