1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-28 12:29:56 +00:00
TiddlyWiki5/tw2/source/tiddlywiki/js/TW21Saver.js
Jeremy Ruston a1c8ac624f Added first pass at support for building TiddlyWiki 2.6.x with TW5
There are still some whitespace and attribute ordering issues, but the
result runs correctly.
2012-05-29 22:02:38 +01:00

43 lines
1.5 KiB
JavaScript
Executable File

//--
//-- TW21Saver (inherits from SaverBase)
//--
function TW21Saver() {}
TW21Saver.prototype = new SaverBase();
TW21Saver.prototype.externalizeTiddler = function(store,tiddler)
{
try {
var extendedAttributes = "";
var usePre = config.options.chkUsePreForStorage;
store.forEachField(tiddler,
function(tiddler,fieldName,value) {
// don't store stuff from the temp namespace
if(typeof value != "string")
value = "";
if(!fieldName.match(/^temp\./))
extendedAttributes += ' %0="%1"'.format([fieldName,value.escapeLineBreaks().htmlEncode()]);
},true);
var created = tiddler.created;
var modified = tiddler.modified;
var attributes = tiddler.creator ? ' creator="' + tiddler.creator.htmlEncode() + '"' : "";
attributes += tiddler.modifier ? ' modifier="' + tiddler.modifier.htmlEncode() + '"' : "";
attributes += (usePre && created == version.date) ? "" :' created="' + created.convertToYYYYMMDDHHMM() + '"';
attributes += (usePre && modified == created) ? "" : ' modified="' + modified.convertToYYYYMMDDHHMM() +'"';
var tags = tiddler.getTags();
if(!usePre || tags)
attributes += ' tags="' + tags.htmlEncode() + '"';
return ('<div %0="%1"%2%3>%4</'+'div>').format([
usePre ? "title" : "tiddler",
tiddler.title.htmlEncode(),
attributes,
extendedAttributes,
usePre ? "\n<pre>" + tiddler.text.htmlEncode() + "</pre>\n" : tiddler.text.escapeLineBreaks().htmlEncode()
]);
} catch (ex) {
throw exceptionText(ex,config.messages.tiddlerSaveError.format([tiddler.title]));
}
};