2011-11-22 17:42:03 +00:00
|
|
|
/*
|
|
|
|
Functions concerned with parsing representations of tiddlers
|
|
|
|
*/
|
|
|
|
|
2011-11-30 17:27:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2011-11-27 09:46:02 +00:00
|
|
|
var utils = require("./Utils.js");
|
2011-11-22 17:42:03 +00:00
|
|
|
|
|
|
|
var tiddlerOutput = exports;
|
|
|
|
|
2011-11-25 19:20:35 +00:00
|
|
|
/*
|
|
|
|
Output a tiddler as a .tid file
|
|
|
|
*/
|
|
|
|
tiddlerOutput.outputTiddler = function(tid) {
|
2011-11-28 17:04:39 +00:00
|
|
|
var result = [],
|
|
|
|
outputAttribute = function(name,value) {
|
2011-11-25 19:20:35 +00:00
|
|
|
result.push(name + ": " + value + "\n");
|
|
|
|
};
|
|
|
|
for(var t in tid.fields) {
|
|
|
|
switch(t) {
|
|
|
|
case "text":
|
|
|
|
// Ignore the text field
|
|
|
|
break;
|
|
|
|
case "tags":
|
|
|
|
// Output tags as a list
|
|
|
|
outputAttribute(t,tiddlerOutput.stringifyTags(tid.fields.tags));
|
|
|
|
break;
|
|
|
|
case "modified":
|
|
|
|
case "created":
|
|
|
|
// Output dates in YYYYMMDDHHMM
|
|
|
|
outputAttribute(t,utils.convertToYYYYMMDDHHMM(tid.fields[t]));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Output other attributes raw
|
|
|
|
outputAttribute(t,tid.fields[t]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push("\n");
|
|
|
|
result.push(tid.fields.text);
|
|
|
|
return result.join("");
|
|
|
|
}
|
|
|
|
|
2011-11-22 17:42:03 +00:00
|
|
|
/*
|
|
|
|
Output a tiddler as an HTML <DIV>
|
|
|
|
out - array to push the output strings
|
|
|
|
tid - the tiddler to be output
|
|
|
|
options - options:
|
|
|
|
omitPrecedingLineFeed - determines if a linefeed is inserted between the <PRE> tag and the text
|
|
|
|
*/
|
2011-11-25 13:27:40 +00:00
|
|
|
tiddlerOutput.outputTiddlerDiv = function(tid) {
|
2011-11-28 17:04:39 +00:00
|
|
|
var result = [],
|
|
|
|
outputAttribute = function(name,value) {
|
|
|
|
result.push(" " + name + "=\"" + value + "\"");
|
|
|
|
};
|
2011-11-22 17:42:03 +00:00
|
|
|
result.push("<div");
|
|
|
|
for(var t in tid.fields) {
|
|
|
|
switch(t) {
|
|
|
|
case "text":
|
|
|
|
// Ignore the text field
|
|
|
|
break;
|
|
|
|
case "tags":
|
|
|
|
// Output tags as a list
|
|
|
|
outputAttribute(t,tiddlerOutput.stringifyTags(tid.fields.tags));
|
|
|
|
break;
|
|
|
|
case "modified":
|
|
|
|
case "created":
|
|
|
|
// Output dates in YYYYMMDDHHMMSS
|
|
|
|
outputAttribute(t,utils.convertToYYYYMMDDHHMM(tid.fields[t]));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Output other attributes raw
|
|
|
|
outputAttribute(t,tid.fields[t]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push(">\n<pre>\n");
|
|
|
|
result.push(utils.htmlEncode(tid.fields.text));
|
|
|
|
result.push("</pre>\n</div>");
|
2011-11-25 13:27:40 +00:00
|
|
|
return result.join("");
|
2011-11-22 17:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tiddlerOutput.stringifyTags = function(tags) {
|
|
|
|
var results = [];
|
|
|
|
for(var t=0; t<tags.length; t++) {
|
|
|
|
if(tags[t].indexOf(" ") !== -1) {
|
|
|
|
results.push("[[" + tags[t] + "]]");
|
|
|
|
} else {
|
|
|
|
results.push(tags[t]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results.join(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
|