diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 703b0178f..3b28ce7b6 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -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"); +}; + })(); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index b62aaca1a..51486e185 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -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())); }; /*