mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Update setTiddlerData() to preserve tiddler dictionaries
Previously, data tiddlers were always being saved in JSON format, regardless of the original format.
This commit is contained in:
parent
823b4fa61b
commit
260080164f
@ -436,4 +436,15 @@ exports.base64Decode = function(string64) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Convert a hashmap into a tiddler dictionary format sequence of name:value pairs
|
||||
*/
|
||||
exports.makeTiddlerDictionary = function(data) {
|
||||
var output = [];
|
||||
for(var name in data) {
|
||||
output.push(name + ": " + data[name]);
|
||||
}
|
||||
return output.join("\n");
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -620,8 +620,17 @@ data: object that can be serialised to JSON
|
||||
fields: optional hashmap of additional tiddler fields to be set
|
||||
*/
|
||||
exports.setTiddlerData = function(title,data,fields) {
|
||||
var tiddler = this.getTiddler(title);
|
||||
this.addTiddler(new $tw.Tiddler(tiddler,fields,{title: title, type: "application/json", text: JSON.stringify(data,null,$tw.config.preferences.jsonSpaces)},this.getModificationFields()));
|
||||
var existingTiddler = this.getTiddler(title),
|
||||
newFields = {
|
||||
title: title
|
||||
};
|
||||
if(existingTiddler && existingTiddler.fields.type === "application/x-tiddler-dictionary") {
|
||||
newFields.text = $tw.utils.makeTiddlerDictionary(data);
|
||||
} else {
|
||||
newFields.type = "application/json";
|
||||
newFields.text = JSON.stringify(data,null,$tw.config.preferences.jsonSpaces);
|
||||
}
|
||||
this.addTiddler(new $tw.Tiddler(existingTiddler,fields,newFields,this.getModificationFields()));
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user