kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Fix slow regexp in importing TiddlyWiki HTML files
rodzic
c35742f916
commit
10c25c1692
|
@ -36,30 +36,35 @@ var parseTiddlerDiv = function(text /* [,fields] */) {
|
|||
}
|
||||
}
|
||||
// Parse the DIV body
|
||||
var divRegExp = /^\s*<div\s+([^>]*)>([(?:\s|\S)]*)<\/div>\s*$/gi,
|
||||
subDivRegExp = /^\s*<pre>([(?:\s|\S)]*)<\/pre>\s*$/gi,
|
||||
attrRegExp = /\s*([^=\s]+)\s*=\s*"([^"]*)"/gi,
|
||||
match = divRegExp.exec(text);
|
||||
var startRegExp = /^\s*<div\s+([^>]*)>(\s*<pre>)?/gi,
|
||||
endRegExp,
|
||||
match = startRegExp.exec(text);
|
||||
if(match) {
|
||||
var subMatch = subDivRegExp.exec(match[2]); // Body of the <DIV> tag
|
||||
if(subMatch) {
|
||||
result.text = subMatch[1];
|
||||
// Old-style DIVs don't have the <pre> tag
|
||||
if(match[2]) {
|
||||
endRegExp = /<\/pre>\s*<\/div>\s*$/gi;
|
||||
} 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) {
|
||||
|
|
Ładowanie…
Reference in New Issue