mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-08 10:59:57 +00:00
1326b12948
Macros need to tolerate missing parameters
46 lines
999 B
JavaScript
46 lines
999 B
JavaScript
/*\
|
|
title: js/macros/image.js
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true */
|
|
"use strict";
|
|
|
|
var Renderer = require("../Renderer.js").Renderer;
|
|
|
|
exports.macro = {
|
|
name: "image",
|
|
types: ["text/html","text/plain"],
|
|
params: {
|
|
src: {byName: "default", type: "tiddler"},
|
|
text: {byName: true, type: "text"},
|
|
alignment: {byName: true, type: "text"}
|
|
},
|
|
execute: function(macroNode,tiddler,store) {
|
|
if(store.tiddlerExists(macroNode.params.src)) {
|
|
var imageTree = store.parseTiddler(macroNode.params.src).tree,
|
|
cloneImage = [];
|
|
for(var t=0; t<imageTree.length; t++) {
|
|
cloneImage.push(imageTree[t].clone());
|
|
}
|
|
if(macroNode.params.text) {
|
|
return [Renderer.ElementNode("div",{
|
|
alt: macroNode.params.text,
|
|
title: macroNode.params.text
|
|
},cloneImage)];
|
|
} else {
|
|
return cloneImage;
|
|
}
|
|
} else {
|
|
return [Renderer.ElementNode("img",{
|
|
href: macroNode.params.src,
|
|
alt: macroNode.params.text,
|
|
title: macroNode.params.text
|
|
})];
|
|
}
|
|
}
|
|
};
|
|
|
|
})();
|