mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-27 19:42:50 +00:00
![Jeremy Ruston](/assets/img/avatar_default.png)
* First commit Cherry-picked from #6666 * Adjust release version number Just in case we decide to make a release before we merge #6666
35 lines
680 B
JavaScript
35 lines
680 B
JavaScript
/*\
|
|
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);
|
|
try {
|
|
data = JSON.parse(title);
|
|
} catch(e) {
|
|
data = undefined;
|
|
}
|
|
if(data !== undefined) {
|
|
results.push(JSON.stringify(data,null,spaces));
|
|
}
|
|
});
|
|
return results;
|
|
};
|
|
|
|
})(); |