mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Wikitext parser: Refactor a poorly written utility function
This commit is contained in:
parent
527638d5e6
commit
d181b96518
@ -386,22 +386,18 @@ Amend the rules used by this instance of the parser
|
|||||||
WikiParser.prototype.amendRules = function(type,names) {
|
WikiParser.prototype.amendRules = function(type,names) {
|
||||||
names = names || [];
|
names = names || [];
|
||||||
// Define the filter function
|
// Define the filter function
|
||||||
var keepFilter;
|
var target;
|
||||||
if(type === "only") {
|
if(type === "only") {
|
||||||
keepFilter = function(name) {
|
target = true;
|
||||||
return names.indexOf(name) !== -1;
|
|
||||||
};
|
|
||||||
} else if(type === "except") {
|
} else if(type === "except") {
|
||||||
keepFilter = function(name) {
|
target = false;
|
||||||
return names.indexOf(name) === -1;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Define a function to process each of our rule arrays
|
// Define a function to process each of our rule arrays
|
||||||
var processRuleArray = function(ruleArray) {
|
var processRuleArray = function(ruleArray) {
|
||||||
for(var t=ruleArray.length-1; t>=0; t--) {
|
for(var t=ruleArray.length-1; t>=0; t--) {
|
||||||
if(!keepFilter(ruleArray[t].rule.name)) {
|
if((names.indexOf(ruleArray[t].rule.name) === -1) === target) {
|
||||||
ruleArray.splice(t,1);
|
ruleArray.splice(t,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user