mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-31 05:22:43 +00:00
41 lines
717 B
JavaScript
41 lines
717 B
JavaScript
![]() |
/*\
|
||
|
title: $:/core/modules/macros/jsontiddler.js
|
||
|
type: application/javascript
|
||
|
module-type: macro
|
||
|
|
||
|
Macro to output a single tiddler to JSON
|
||
|
|
||
|
\*/
|
||
|
(function(){
|
||
|
|
||
|
/*jslint node: true, browser: true */
|
||
|
/*global $tw: false */
|
||
|
"use strict";
|
||
|
|
||
|
/*
|
||
|
Information about this macro
|
||
|
*/
|
||
|
|
||
|
exports.name = "jsontiddler";
|
||
|
|
||
|
exports.params = [
|
||
|
{name: "title"}
|
||
|
];
|
||
|
|
||
|
/*
|
||
|
Run the macro
|
||
|
*/
|
||
|
exports.run = function(title) {
|
||
|
title = title || this.getVariable("currentTiddler");
|
||
|
var tiddler = !!title && this.wiki.getTiddler(title),
|
||
|
fields = new Object();
|
||
|
if(tiddler) {
|
||
|
for(var field in tiddler.fields) {
|
||
|
fields[field] = tiddler.getFieldString(field);
|
||
|
}
|
||
|
}
|
||
|
return JSON.stringify(fields,null,$tw.config.preferences.jsonSpaces);
|
||
|
};
|
||
|
|
||
|
})();
|