mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +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:
|
||||
|
||||
```
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
@ -40,17 +41,19 @@ We make a new tiddler, set its `type` and `module-type` appropriately, and begin
|
||||
// TODO
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
For the example filter syntax, our function will be called with
|
||||
|
||||
* 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
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
@ -64,11 +67,13 @@ We could implement the operator by iterating over the input tiddlers and explici
|
||||
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.
|
||||
|
||||
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(){
|
||||
"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`:
|
||||
|
||||
var include = operator.prefix !== "!";
|
||||
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 !== "!";`
|
||||
|
||||
! 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…
Reference in New Issue
Block a user