mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-02-18 16:09:52 +00:00
Compare commits
4 Commits
master
...
element-ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f29de0cb44 | ||
|
|
a14cd291ac | ||
|
|
b27d102d55 | ||
|
|
9aaab87b87 |
@@ -25,7 +25,6 @@ Render this widget into the DOM
|
|||||||
*/
|
*/
|
||||||
ElementWidget.prototype.render = function(parent,nextSibling) {
|
ElementWidget.prototype.render = function(parent,nextSibling) {
|
||||||
this.parentDomNode = parent;
|
this.parentDomNode = parent;
|
||||||
this.computeAttributes();
|
|
||||||
// Neuter blacklisted elements
|
// Neuter blacklisted elements
|
||||||
this.tag = this.parseTreeNode.tag;
|
this.tag = this.parseTreeNode.tag;
|
||||||
if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) {
|
if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) {
|
||||||
@@ -42,6 +41,8 @@ ElementWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
|
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
|
||||||
this.tag = "h" + headingLevel;
|
this.tag = "h" + headingLevel;
|
||||||
}
|
}
|
||||||
|
// Compute the attributes, mapping the element tag if needed
|
||||||
|
this.computeAttributes();
|
||||||
// Select the namespace for the tag
|
// Select the namespace for the tag
|
||||||
var XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml",
|
var XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml",
|
||||||
tagNamespaces = {
|
tagNamespaces = {
|
||||||
@@ -99,4 +100,25 @@ ElementWidget.prototype.refresh = function(changedTiddlers) {
|
|||||||
return this.refreshChildren(changedTiddlers) || hasChangedAttributes;
|
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;
|
exports.element = ElementWidget;
|
||||||
|
|||||||
18
editions/test/tiddlers/tests/data/element-mapping/Basic.tid
Normal file
18
editions/test/tiddlers/tests/data/element-mapping/Basic.tid
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
title: ElementMapping/Basic
|
||||||
|
description: Mapping one element to another
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
|
||||||
|
<!-- Map <p> to <div>, adding the class my-class -->
|
||||||
|
\define tv-map-p() div
|
||||||
|
|
||||||
|
This is a paragraph
|
||||||
|
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<div data-element-mapping-from="p">This is a paragraph</div>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
title: ElementMapping/BasicWithClass
|
||||||
|
description: Mapping one element to another with an added class
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
|
||||||
|
<!-- Map <p> to <div>, adding the class my-class -->
|
||||||
|
\define tv-map-p() div
|
||||||
|
\define tv-map-p-class() my-class
|
||||||
|
|
||||||
|
This is a paragraph
|
||||||
|
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<div class="my-class" data-element-mapping-from="p">This is a paragraph</div>
|
||||||
Reference in New Issue
Block a user