mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +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) {
|
||||
names = names || [];
|
||||
// Define the filter function
|
||||
var keepFilter;
|
||||
var target;
|
||||
if(type === "only") {
|
||||
keepFilter = function(name) {
|
||||
return names.indexOf(name) !== -1;
|
||||
};
|
||||
target = true;
|
||||
} else if(type === "except") {
|
||||
keepFilter = function(name) {
|
||||
return names.indexOf(name) === -1;
|
||||
};
|
||||
target = false;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// Define a function to process each of our rule arrays
|
||||
var processRuleArray = function(ruleArray) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user