diff --git a/js/Recipe.js b/js/Recipe.js index 17a03b295..d0c2e1368 100644 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -28,9 +28,7 @@ this.ingredients = { */ var tiddler = require("./Tiddler.js"), - tiddlerInput = require("./TiddlerInput.js"), - tiddlerOutput = require("./TiddlerOutput.js"), - utils = require("./TiddlerUtils.js"), + tiddlerUtils = require("./TiddlerUtils.js"), tiddlywiki = require("./TiddlyWiki.js"), fs = require("fs"), path = require("path"), @@ -104,11 +102,11 @@ Recipe.prototype.readIngredient = function(dirname,filepath) { title: basename }; // Read the tiddler file - fields = tiddlerInput.parseTiddler(fs.readFileSync(fullpath,"utf8"),extname,fields); + fields = tiddlerUtils.parseTiddler(fs.readFileSync(fullpath,"utf8"),extname,fields); // Check for the .meta file var metafile = fullpath + ".meta"; if(path.existsSync(metafile)) { - fields = tiddlerInput.parseMetaDataBlock(fs.readFileSync(metafile,"utf8"),fields); + fields = tiddlerUtils.parseMetaDataBlock(fs.readFileSync(metafile,"utf8"),fields); } return fields; } @@ -166,7 +164,7 @@ Recipe.ingredientOutputter = { // Ordinary tiddlers are output as a
for(var t=0; t -
The text of the tiddler (without the expected HTML encoding).
-
-
- -Note that the field attributes are HTML encoded, but that the body of the
 tag is not.
-*/
-tiddlerInput.parseTiddlerDiv = function(text,fields) {
-	if(fields === undefined) {
-		var fields = {};
-	}
-	var divRegExp = /^\s*]*)>((?:.|\n)*)<\/div>\s*$/gi;
-	var subDivRegExp = /^(?:\s*
)((?:.|\n)*)(?:<\/pre>\s*)$/gi;
-	var attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi;
-	var match = divRegExp.exec(text);
-	if(match) {
-		var subMatch = subDivRegExp.exec(match[2]); // Body of the 
tag - if(subMatch) { - fields.text = subMatch[1]; - } else { - fields.text = match[2]; - } - do { - var attrMatch = attrRegExp.exec(match[1]); - if(attrMatch) { - var name = attrMatch[1]; - var value = attrMatch[2]; - fields[name] = tiddlerInput.parseMetaDataItem(name,value); - } - } while(attrMatch); - } - return fields; -} - -/* -Parse a single metadata field/value pair and return the value as the appropriate data type -*/ -tiddlerInput.parseMetaDataItem = function(field,value) { - var result; - switch(field) { - case "modified": - case "created": - result = utils.convertFromYYYYMMDDHHMMSS(value); - break; - case "tags": - var parser = new argParser.ArgParser(value,{noNames: true}); - result = parser.getValuesByName("",""); - break; - default: - result = value; - break; - } - return result; -} diff --git a/js/TiddlerOutput.js b/js/TiddlerOutput.js deleted file mode 100644 index eb7d87f1b..000000000 --- a/js/TiddlerOutput.js +++ /dev/null @@ -1,63 +0,0 @@ -/* -Functions concerned with parsing representations of tiddlers -*/ - -var argParser = require("./ArgParser.js"), - utils = require("./Utils.js"); - -var tiddlerOutput = exports; - -/* -Output a tiddler as an HTML
-out - array to push the output strings -tid - the tiddler to be output -options - options: - omitPrecedingLineFeed - determines if a linefeed is inserted between the
 tag and the text
-*/
-tiddlerOutput.outputTiddlerDiv = function(out,tid,options) {
-	var result = [];
-	var outputAttribute = function(name,value) {
-		result.push(" " + name + "=\"" + value + "\"");
-	};
-	result.push("\n
");
-	if(!(options && options.omitPrecedingLineFeed))
-		result.push("\n");
-	result.push(utils.htmlEncode(tid.fields.text));
-	result.push("
\n
"); - out.push(result.join("")); -} - -tiddlerOutput.stringifyTags = function(tags) { - var results = []; - for(var t=0; t +
The text of the tiddler (without the expected HTML encoding).
+
+
+ +Note that the field attributes are HTML encoded, but that the body of the
 tag is not.
+*/
+tiddlerUtils.parseTiddlerDiv = function(text,fields) {
+	if(fields === undefined) {
+		var fields = {};
+	}
+	var divRegExp = /^\s*]*)>((?:.|\n)*)<\/div>\s*$/gi;
+	var subDivRegExp = /^(?:\s*
)((?:.|\n)*)(?:<\/pre>\s*)$/gi;
+	var attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi;
+	var match = divRegExp.exec(text);
+	if(match) {
+		var subMatch = subDivRegExp.exec(match[2]); // Body of the 
tag + if(subMatch) { + fields.text = subMatch[1]; + } else { + fields.text = match[2]; + } + do { + var attrMatch = attrRegExp.exec(match[1]); + if(attrMatch) { + var name = attrMatch[1]; + var value = attrMatch[2]; + fields[name] = tiddlerUtils.parseMetaDataItem(name,value); + } + } while(attrMatch); + } + return fields; +} + +// Output a tiddler as an HTML
+// out - array to push the output strings +// tid - the tiddler to be output +// options - options: +// omitPrecedingLineFeed - determines if a linefeed is inserted between the
 tag and the text
+tiddlerUtils.outputTiddlerDiv = function(out,tid,options) {
+	var result = [];
+	var outputAttribute = function(name,value) {
+		result.push(" " + name + "=\"" + value + "\"");
+	};
+	result.push("\n
");
+	if(!(options && options.omitPrecedingLineFeed))
+		result.push("\n");
+	result.push(tiddlerUtils.htmlEncode(tid.fields.text));
+	result.push("
\n
"); + out.push(result.join("")); +} + +tiddlerUtils.stringifyTags = function(tags) { + var results = []; + for(var t=0; t to ">" and " to """ +tiddlerUtils.htmlEncode = function(s) +{ + return s.replace(/&/mg,"&").replace(//mg,">").replace(/\"/mg,"""); +}; + +// Convert "&" to &, "<" to <, ">" to > and """ to " +tiddlerUtils.htmlDecode = function(s) +{ + return s.replace(/</mg,"<").replace(/>/mg,">").replace(/"/mg,"\"").replace(/&/mg,"&"); +}; + diff --git a/js/Utils.js b/js/Utils.js deleted file mode 100644 index c3c39b7ab..000000000 --- a/js/Utils.js +++ /dev/null @@ -1,74 +0,0 @@ -/* -Various static utility functions. - -This file is a bit of a dumping ground; the expectation is that most of these functions will be refactored. -*/ - -var utils = exports; - -// Pad a string to a certain length with zeros -utils.zeroPad = function(n,d) -{ - var s = n.toString(); - if(s.length < d) - s = "000000000000000000000000000".substr(0,d-s.length) + s; - return s; -}; - -// Convert a date to local YYYYMMDDHHMM string format -utils.convertToLocalYYYYMMDDHHMM = function(date) -{ - return date.getFullYear() + utils.zeroPad(date.getMonth()+1,2) + utils.zeroPad(date.getDate(),2) + utils.zeroPad(date.getHours(),2) + utils.zeroPad(date.getMinutes(),2); -}; - -// Convert a date to UTC YYYYMMDDHHMM string format -utils.convertToYYYYMMDDHHMM = function(date) -{ - return date.getUTCFullYear() + utils.zeroPad(date.getUTCMonth()+1,2) + utils.zeroPad(date.getUTCDate(),2) + utils.zeroPad(date.getUTCHours(),2) + utils.zeroPad(date.getUTCMinutes(),2); -}; - -// Convert a date to UTC YYYYMMDD.HHMMSSMMM string format -utils.convertToYYYYMMDDHHMMSSMMM = function(date) -{ - return date.getUTCFullYear() + utils.zeroPad(date.getUTCMonth()+1,2) + utils.zeroPad(date.getUTCDate(),2) + "." + utils.zeroPad(date.getUTCHours(),2) + utils.zeroPad(date.getUTCMinutes(),2) + utils.zeroPad(date.getUTCSeconds(),2) + utils.zeroPad(date.getUTCMilliseconds(),3) +"0"; -}; - -// Create a date from a UTC YYYYMMDDHHMM format string -utils.convertFromYYYYMMDDHHMM = function(d) -{ - d = d?d.replace(/[^0-9]/g, ""):""; - return utils.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,12)); -}; - -// Create a date from a UTC YYYYMMDDHHMMSS format string -utils.convertFromYYYYMMDDHHMMSS = function(d) -{ - d = d?d.replace(/[^0-9]/g, ""):""; - return utils.convertFromYYYYMMDDHHMMSSMMM(d.substr(0,14)); -}; - -// Create a date from a UTC YYYYMMDDHHMMSSMMM format string -utils.convertFromYYYYMMDDHHMMSSMMM = function(d) -{ - d = d ? d.replace(/[^0-9]/g, "") : ""; - return new Date(Date.UTC(parseInt(d.substr(0,4),10), - parseInt(d.substr(4,2),10)-1, - parseInt(d.substr(6,2),10), - parseInt(d.substr(8,2)||"00",10), - parseInt(d.substr(10,2)||"00",10), - parseInt(d.substr(12,2)||"00",10), - parseInt(d.substr(14,3)||"000",10))); -}; - -// Convert & to "&", < to "<", > to ">" and " to """ -utils.htmlEncode = function(s) -{ - return s.replace(/&/mg,"&").replace(//mg,">").replace(/\"/mg,"""); -}; - -// Convert "&" to &, "<" to <, ">" to > and """ to " -utils.htmlDecode = function(s) -{ - return s.replace(/</mg,"<").replace(/>/mg,">").replace(/"/mg,"\"").replace(/&/mg,"&"); -}; -