mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 20:10:03 +00:00
6fc5c70ace
New export button appears as a page control toolbar button, a tiddler toolbar button, and a button in the advanced search filter tab. Initially supports exporting as static HTML, CSV, JSON or `.tid` file. Still to do: * Made the exporter descriptions translatable * Hide the export button by default * User docs * Cleaning up the existing templates (eg, `$:/core/templates/alltiddlers.template.html` should work by transcluding `$:/core/templates/exporters/Static`) * Docs for the new macros `exportButton`, `csvtiddlers` and `jsontiddlers` Issues: * OS X Numbers refuses to open CSV files that have been generated in Chrome, because it thinks they’ve been downloaded from the Internet. Firefox works OK * The export button won’t work within the tiddler info panel, or from the *more* popup (this is because we don’t support nested popups)
45 lines
808 B
JavaScript
45 lines
808 B
JavaScript
/*\
|
|
title: $:/core/modules/macros/jsontiddlers.js
|
|
type: application/javascript
|
|
module-type: macro
|
|
|
|
Macro to output tiddlers matching a filter to JSON
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Information about this macro
|
|
*/
|
|
|
|
exports.name = "jsontiddlers";
|
|
|
|
exports.params = [
|
|
{name: "filter"}
|
|
];
|
|
|
|
/*
|
|
Run the macro
|
|
*/
|
|
exports.run = function(filter) {
|
|
var tiddlers = this.wiki.filterTiddlers(filter),
|
|
data = [];
|
|
for(var t=0;t<tiddlers.length; t++) {
|
|
var tiddler = this.wiki.getTiddler(tiddlers[t]);
|
|
if(tiddler) {
|
|
var fields = new Object();
|
|
for(var field in tiddler.fields) {
|
|
fields[field] = tiddler.getFieldString(field);
|
|
}
|
|
data.push(fields);
|
|
}
|
|
}
|
|
return JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
|
|
};
|
|
|
|
})();
|