mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-03 23:24:07 +00:00
Extend jsontiddlers macro to generate unformatted output
This commit is contained in:
parent
a4593b8e3d
commit
3df1f9c9d0
@ -19,14 +19,15 @@ Information about this macro
|
|||||||
exports.name = "jsontiddlers";
|
exports.name = "jsontiddlers";
|
||||||
|
|
||||||
exports.params = [
|
exports.params = [
|
||||||
{name: "filter"}
|
{name: "filter"},
|
||||||
|
{name: "spaces"}
|
||||||
];
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Run the macro
|
Run the macro
|
||||||
*/
|
*/
|
||||||
exports.run = function(filter) {
|
exports.run = function(filter,spaces) {
|
||||||
return this.wiki.getTiddlersAsJson(filter);
|
return this.wiki.getTiddlersAsJson(filter,spaces);
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -660,8 +660,9 @@ exports.getTiddlerAsJson = function(title) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getTiddlersAsJson = function(filter) {
|
exports.getTiddlersAsJson = function(filter,spaces) {
|
||||||
var tiddlers = this.filterTiddlers(filter),
|
var tiddlers = this.filterTiddlers(filter),
|
||||||
|
spaces = (spaces === undefined) ? $tw.config.preferences.jsonSpaces : spaces,
|
||||||
data = [];
|
data = [];
|
||||||
for(var t=0;t<tiddlers.length; t++) {
|
for(var t=0;t<tiddlers.length; t++) {
|
||||||
var tiddler = this.getTiddler(tiddlers[t]);
|
var tiddler = this.getTiddler(tiddlers[t]);
|
||||||
@ -673,7 +674,7 @@ exports.getTiddlersAsJson = function(filter) {
|
|||||||
data.push(fields);
|
data.push(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
|
return JSON.stringify(data,null,spaces);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
created: 20150221152226000
|
created: 20150221152226000
|
||||||
modified: 20150221154213000
|
modified: 20200204135513721
|
||||||
tags: Macros [[Core Macros]]
|
tags: Macros [[Core Macros]]
|
||||||
title: jsontiddlers Macro
|
title: jsontiddlers Macro
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -13,3 +13,5 @@ An example can be seen in the [[template tiddler for JSON exports|$:/core/templa
|
|||||||
|
|
||||||
;filter
|
;filter
|
||||||
: A [[filter|Filters]] selecting which tiddlers to include
|
: A [[filter|Filters]] selecting which tiddlers to include
|
||||||
|
;spaces
|
||||||
|
: An optional number of spaces to use for formatting the JSON. Defaults to 4, with blank or zero resulting in packed JSON with no formatting spaces
|
||||||
|
Loading…
x
Reference in New Issue
Block a user