1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-24 19:24:50 +00:00

Fix slow regexp in importing TiddlyWiki HTML files

This commit is contained in:
Jermolene
2013-12-23 08:54:33 +00:00
parent c35742f916
commit 10c25c1692

View File

@@ -36,18 +36,23 @@ var parseTiddlerDiv = function(text /* [,fields] */) {
} }
} }
// Parse the DIV body // Parse the DIV body
var divRegExp = /^\s*<div\s+([^>]*)>([(?:\s|\S)]*)<\/div>\s*$/gi, var startRegExp = /^\s*<div\s+([^>]*)>(\s*<pre>)?/gi,
subDivRegExp = /^\s*<pre>([(?:\s|\S)]*)<\/pre>\s*$/gi, endRegExp,
attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi, match = startRegExp.exec(text);
match = divRegExp.exec(text);
if(match) { if(match) {
var subMatch = subDivRegExp.exec(match[2]); // Body of the <DIV> tag // Old-style DIVs don't have the <pre> tag
if(subMatch) { if(match[2]) {
result.text = subMatch[1]; endRegExp = /<\/pre>\s*<\/div>\s*$/gi;
} else { } else {
result.text = match[2]; endRegExp = /<\/div>\s*$/gi;
} }
var attrMatch; var endMatch = endRegExp.exec(text);
if(endMatch) {
// Extract the text
result.text = text.substring(match.index + match[0].length,endMatch.index);
// Process the attributes
var attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi,
attrMatch;
do { do {
attrMatch = attrRegExp.exec(match[1]); attrMatch = attrRegExp.exec(match[1]);
if(attrMatch) { if(attrMatch) {
@@ -57,9 +62,9 @@ var parseTiddlerDiv = function(text /* [,fields] */) {
} }
} while(attrMatch); } while(attrMatch);
return result; return result;
} else {
return undefined;
} }
}
return undefined;
}; };
exports["application/x-tiddler-html-div"] = function(text,fields) { exports["application/x-tiddler-html-div"] = function(text,fields) {