1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fixed tiddler loading in the face of Windows style crlf line breaks

This commit is contained in:
Jeremy Ruston 2012-05-09 13:48:34 +01:00
parent cfcb255c23
commit 998bd07ef9

View File

@ -124,7 +124,7 @@ $tw.utils.parseDate = function(value) {
// Parse a string array from a bracketted list // Parse a string array from a bracketted list
$tw.utils.parseStringArray = function(value) { $tw.utils.parseStringArray = function(value) {
if(typeof value === "string") { if(typeof value === "string") {
var memberRegExp = /(?:\[\[([^\]]+)\]\])|([^\s$]+)/mg, var memberRegExp = /(?:\[\[([^\]]+)\]\])|([^\s]+)/mg,
results = [], results = [],
match; match;
do { 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 // 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) { $tw.utils.parseFields = function(text,fields) {
text.split("\n").forEach(function(line) { text.split(/\r?\n/mg).forEach(function(line) {
var p = line.indexOf(":"); var p = line.indexOf(":");
if(p !== -1) { if(p !== -1) {
var field = line.substr(0, p).trim(), 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); match = headerCommentRegExp.exec(text);
fields.text = text; fields.text = text;
if(match) { 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]; return [fields];
} }
}); });
$tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/tid","tiddlerdeserializer",{ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/tid","tiddlerdeserializer",{
"application/x-tiddler": function(text,fields) { "application/x-tiddler": function(text,fields) {
fields.type = "text/x-tiddlywiki"; var split = text.split(/\r?\n\r?\n/mg);
var split = text.indexOf("\n\n"); if(split.length > 1) {
if(split !== -1) { fields = $tw.utils.parseFields(split[0],fields);
fields = $tw.utils.parseFields(text.substr(0,split),fields); fields.text = split.slice(1).join("\n\n");
fields.text = text.substr(split + 2);
} else { } else {
fields.text = text; fields.text = text;
} }