From 998bd07ef9d92b075b95203d8ec0778d85a7a174 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 9 May 2012 13:48:34 +0100 Subject: [PATCH] Fixed tiddler loading in the face of Windows style crlf line breaks --- core/boot.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/boot.js b/core/boot.js index be2cfeffa..1b8252451 100644 --- a/core/boot.js +++ b/core/boot.js @@ -124,7 +124,7 @@ $tw.utils.parseDate = function(value) { // Parse a string array from a bracketted list $tw.utils.parseStringArray = function(value) { if(typeof value === "string") { - var memberRegExp = /(?:\[\[([^\]]+)\]\])|([^\s$]+)/mg, + var memberRegExp = /(?:\[\[([^\]]+)\]\])|([^\s]+)/mg, results = [], match; do { @@ -143,7 +143,7 @@ $tw.utils.parseStringArray = function(value) { // Parse a block of name:value fields. The `fields` object is used as the basis for the return value $tw.utils.parseFields = function(text,fields) { - text.split("\n").forEach(function(line) { + text.split(/\r?\n/mg).forEach(function(line) { var p = line.indexOf(":"); if(p !== -1) { var field = line.substr(0, p).trim(), @@ -389,18 +389,17 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/js","t match = headerCommentRegExp.exec(text); fields.text = text; if(match) { - fields = $tw.utils.parseFields(match[1].split("\n\n")[0],fields); + fields = $tw.utils.parseFields(match[1].split(/\r?\n\r?\n/mg)[0],fields); } return [fields]; } }); $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/tid","tiddlerdeserializer",{ "application/x-tiddler": function(text,fields) { - fields.type = "text/x-tiddlywiki"; - var split = text.indexOf("\n\n"); - if(split !== -1) { - fields = $tw.utils.parseFields(text.substr(0,split),fields); - fields.text = text.substr(split + 2); + var split = text.split(/\r?\n\r?\n/mg); + if(split.length > 1) { + fields = $tw.utils.parseFields(split[0],fields); + fields.text = split.slice(1).join("\n\n"); } else { fields.text = text; }