/*\ title: $:/core/modules/deserializers.js type: application/javascript module-type: tiddlerdeserializer Functions to deserialise tiddlers from a block of text \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; /* Utility function to parse an old-style tiddler DIV in a *.tid file. It looks like this:
The text of the tiddler (without the expected HTML encoding).
tag is not encoded. When these tiddler DIVs are encountered within a TiddlyWiki HTML file then the body is encoded in the usual way. */ var parseTiddlerDiv = function(text /* [,fields] */) { // Slot together the default results var result = {}; if(arguments.length > 1) { for(var f=1; f]*)>(\s* )?/gi, endRegExp, match = startRegExp.exec(text); if(match) { // Old-style DIVs don't have thetag if(match[2]) { endRegExp = /<\/pre>\s*<\/div>\s*$/gi; } else { endRegExp = /<\/div>\s*$/gi; } var endMatch = endRegExp.exec(text); if(endMatch) { // Extract the text result.text = text.substring(match.index + match[0].length,endMatch.index); // Process the attributes var attrRegExp = /\s*([^=\s]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi, attrMatch; do { attrMatch = attrRegExp.exec(match[1]); if(attrMatch) { var name = attrMatch[1]; var value = attrMatch[2] !== undefined ? attrMatch[2] : attrMatch[3]; result[name] = value; } } while(attrMatch); return result; } } return undefined; }; exports["application/x-tiddler-html-div"] = function(text,fields) { return [parseTiddlerDiv(text,fields)]; }; exports["application/json"] = function(text,fields) { var incoming = JSON.parse(text), results = []; if($tw.utils.isArray(incoming)) { for(var t=0; t