2022-06-10 08:29:56 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/filters/format/json.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: formatfilteroperator
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
|
|
|
exports.json = function(source,operand,options) {
|
|
|
|
var results = [],
|
|
|
|
spaces = null;
|
|
|
|
if(operand) {
|
|
|
|
spaces = /^\d+$/.test(operand) ? parseInt(operand,10) : operand;
|
|
|
|
}
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
var data = $tw.utils.parseJSONSafe(title);
|
2022-06-11 16:29:20 +00:00
|
|
|
try {
|
|
|
|
data = JSON.parse(title);
|
|
|
|
} catch(e) {
|
|
|
|
data = undefined;
|
|
|
|
}
|
|
|
|
if(data !== undefined) {
|
|
|
|
results.push(JSON.stringify(data,null,spaces));
|
|
|
|
}
|
2022-06-10 08:29:56 +00:00
|
|
|
});
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|