Extend jsontiddlers macro to generate unformatted output

This commit is contained in:
Jeremy Ruston 2020-02-04 13:57:24 +00:00
parent a4593b8e3d
commit 3df1f9c9d0
3 changed files with 10 additions and 6 deletions

View File

@ -19,14 +19,15 @@ Information about this macro
exports.name = "jsontiddlers";
exports.params = [
{name: "filter"}
{name: "filter"},
{name: "spaces"}
];
/*
Run the macro
*/
exports.run = function(filter) {
return this.wiki.getTiddlersAsJson(filter);
exports.run = function(filter,spaces) {
return this.wiki.getTiddlersAsJson(filter,spaces);
};
})();

View File

@ -660,8 +660,9 @@ exports.getTiddlerAsJson = function(title) {
}
};
exports.getTiddlersAsJson = function(filter) {
exports.getTiddlersAsJson = function(filter,spaces) {
var tiddlers = this.filterTiddlers(filter),
spaces = (spaces === undefined) ? $tw.config.preferences.jsonSpaces : spaces,
data = [];
for(var t=0;t<tiddlers.length; t++) {
var tiddler = this.getTiddler(tiddlers[t]);
@ -673,7 +674,7 @@ exports.getTiddlersAsJson = function(filter) {
data.push(fields);
}
}
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
return JSON.stringify(data,null,spaces);
};
/*

View File

@ -1,5 +1,5 @@
created: 20150221152226000
modified: 20150221154213000
modified: 20200204135513721
tags: Macros [[Core Macros]]
title: jsontiddlers Macro
type: text/vnd.tiddlywiki
@ -13,3 +13,5 @@ An example can be seen in the [[template tiddler for JSON exports|$:/core/templa
;filter
: 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