mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-20 04:50:03 +00:00
Assorted wikitext fixes
This commit is contained in:
parent
b23d53e9b0
commit
d806f1d0f1
@ -33,6 +33,7 @@ Suppose we want to make a filter operator that returns every other tiddler from
|
|||||||
|
|
||||||
We make a new tiddler, set its `type` and `module-type` appropriately, and begin writing the code:
|
We make a new tiddler, set its `type` and `module-type` appropriately, and begin writing the code:
|
||||||
|
|
||||||
|
```
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -40,17 +41,19 @@ We make a new tiddler, set its `type` and `module-type` appropriately, and begin
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
For the example filter syntax, our function will be called with
|
For the example filter syntax, our function will be called with
|
||||||
|
|
||||||
* source: an iterator over all the tiddlers tagged as `interesting`
|
* source: an iterator over all the tiddlers tagged as `interesting`
|
||||||
* operator: an object {operator: "everyother", operand: ""}
|
* operator: an object `{operator: "everyother", operand: ""}`
|
||||||
* options: an object with the current Wiki object and a widget object, neither of which we need
|
* options: an object with the current Wiki object and a widget object, neither of which we need
|
||||||
|
|
||||||
As is usually the case, we don't care about `operator.operator` here (since that information has already been used to look up our function); we also don't care about `operator.operand`, since there is no meaningful operand for this operation.
|
As is usually the case, we don't care about `operator.operator` here (since that information has already been used to look up our function); we also don't care about `operator.operand`, since there is no meaningful operand for this operation.
|
||||||
|
|
||||||
We could implement the operator by iterating over the input tiddlers and explicitly building a result array of titles:
|
We could implement the operator by iterating over the input tiddlers and explicitly building a result array of titles:
|
||||||
|
|
||||||
|
```
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -64,11 +67,13 @@ We could implement the operator by iterating over the input tiddlers and explici
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
That is, we supply a callback to `source` that negates `include` each time through (in order to grab every other result) and pushes the `title` of every other tiddler onto the result.
|
That is, we supply a callback to `source` that negates `include` each time through (in order to grab every other result) and pushes the `title` of every other tiddler onto the result.
|
||||||
|
|
||||||
Alternatively, we can return our own iterator, by returning a function that accepts a similar callback and only calls it on every other tiddler:
|
Alternatively, we can return our own iterator, by returning a function that accepts a similar callback and only calls it on every other tiddler:
|
||||||
|
|
||||||
|
```
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -82,11 +87,10 @@ Alternatively, we can return our own iterator, by returning a function that acce
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
Either way, we could interpret the `!` flag on the filter, if present, to mean that we want the //other// half of the tiddlers, by using it to set the initial value of `include`:
|
Either way, we could interpret the `!` flag on the filter, if present, to mean that we want the //other// half of the tiddlers, by using it to set the initial value of `include`: `var include = operator.prefix !== "!";`
|
||||||
|
|
||||||
var include = operator.prefix !== "!";
|
|
||||||
|
|
||||||
! Filter Behaviour
|
! Filter Behaviour
|
||||||
|
|
||||||
As with [JavaScript Macros], filter operators should not make modifications to tiddlers, but only return a list of tiddlers or a tiddler iterator.
|
As with [[JavaScript Macros]], filter operators should not make modifications to tiddlers, but only return a list of tiddlers or a tiddler iterator.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user