mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-17 23:31:22 +00:00
Add support for macro modules
Now JavaScript macros can be defined in "macro" modules
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/makedatauri.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Macro to convert the content of a tiddler to a data URI
|
||||
|
||||
<<makedatauri text:"Text to be converted" type:"text/vnd.tiddlywiki">>
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Information about this macro
|
||||
*/
|
||||
|
||||
exports.name = "makedatauri";
|
||||
|
||||
exports.params = [
|
||||
{name: "text"},
|
||||
{name: "type"}
|
||||
];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(text,type) {
|
||||
type = type || "text/vnd.tiddlywiki";
|
||||
var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"],
|
||||
isBase64 = typeInfo.encoding === "base64",
|
||||
parts = [];
|
||||
parts.push("data:");
|
||||
parts.push(type);
|
||||
parts.push(isBase64 ? ";base64" : "");
|
||||
parts.push(",");
|
||||
parts.push(isBase64 ? text : encodeURIComponent(text));
|
||||
return parts.join("");
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,30 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/version.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Macro to return the TiddlyWiki core version number
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Information about this macro
|
||||
*/
|
||||
|
||||
exports.name = "version";
|
||||
|
||||
exports.params = [];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function() {
|
||||
return $tw.version;
|
||||
};
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user