mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-24 03:04:51 +00:00
Fix slow regexp in importing TiddlyWiki HTML files
This commit is contained in:
@@ -36,30 +36,35 @@ 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 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 {
|
||||||
|
attrMatch = attrRegExp.exec(match[1]);
|
||||||
|
if(attrMatch) {
|
||||||
|
var name = attrMatch[1];
|
||||||
|
var value = attrMatch[2];
|
||||||
|
result[name] = value;
|
||||||
|
}
|
||||||
|
} while(attrMatch);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
var attrMatch;
|
|
||||||
do {
|
|
||||||
attrMatch = attrRegExp.exec(match[1]);
|
|
||||||
if(attrMatch) {
|
|
||||||
var name = attrMatch[1];
|
|
||||||
var value = attrMatch[2];
|
|
||||||
result[name] = value;
|
|
||||||
}
|
|
||||||
} while(attrMatch);
|
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user