mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 04:09:09 +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
|
fields: optional hashmap of additional tiddler fields to be set
|
||||||
*/
|
*/
|
||||||
exports.setTiddlerData = function(title,data,fields) {
|
exports.setTiddlerData = function(title,data,fields) {
|
||||||
var tiddler = this.getTiddler(title);
|
var existingTiddler = 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()));
|
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