mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Add strict mode to tag operator
This commit is contained in:
parent
c460cc03a4
commit
c65d08240b
@ -17,13 +17,23 @@ Export our filter function
|
|||||||
*/
|
*/
|
||||||
exports.tag = function(source,operator,options) {
|
exports.tag = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
|
if((operator.suffix || "").toLowerCase() === "strict" && !operator.operand) {
|
||||||
|
// New semantics:
|
||||||
|
// Always return copy of input if operator.operand is missing
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(title);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Old semantics:
|
||||||
if(operator.prefix === "!") {
|
if(operator.prefix === "!") {
|
||||||
|
// Returns a copy of the input if operator.operand is missing
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
if(tiddler && !tiddler.hasTag(operator.operand)) {
|
if(tiddler && !tiddler.hasTag(operator.operand)) {
|
||||||
results.push(title);
|
results.push(title);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// Returns empty results if operator.operand is missing
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
if(tiddler && tiddler.hasTag(operator.operand)) {
|
if(tiddler && tiddler.hasTag(operator.operand)) {
|
||||||
results.push(title);
|
results.push(title);
|
||||||
@ -31,6 +41,7 @@ exports.tag = function(source,operator,options) {
|
|||||||
});
|
});
|
||||||
results = options.wiki.sortByList(results,operator.operand);
|
results = options.wiki.sortByList(results,operator.operand);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,18 +1,23 @@
|
|||||||
|
caption: tag
|
||||||
created: 20140410103123179
|
created: 20140410103123179
|
||||||
modified: 20150203191853000
|
modified: 20161126122900712
|
||||||
|
op-input: a [[selection of titles|Title Selection]]
|
||||||
|
op-neg-output: those input tiddlers that do <<.em not>> have tag <<.place T>>
|
||||||
|
op-output: those input tiddlers that have tag <<.place T>>
|
||||||
|
op-parameter: the title of a [[tag|Tagging]]
|
||||||
|
op-parameter-name: T
|
||||||
|
op-purpose: filter the input by tag
|
||||||
|
op-suffix: <<.from-version "5.1.14">> optional `strict` flag
|
||||||
|
op-suffix-name: S
|
||||||
tags: [[Filter Operators]] [[Common Operators]] [[Tag Operators]] [[Negatable Operators]]
|
tags: [[Filter Operators]] [[Common Operators]] [[Tag Operators]] [[Negatable Operators]]
|
||||||
title: tag Operator
|
title: tag Operator
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
caption: tag
|
|
||||||
op-purpose: filter the input by tag
|
|
||||||
op-input: a [[selection of titles|Title Selection]]
|
|
||||||
op-parameter: the title of a [[tag|Tagging]]
|
|
||||||
op-parameter-name: T
|
|
||||||
op-output: those input tiddlers that have tag <<.place T>>
|
|
||||||
op-neg-output: those input tiddlers that do <<.em not>> have tag <<.place T>>
|
|
||||||
|
|
||||||
The output is [[sorted|Order of Tagged Tiddlers]] using the tag's <<.field list>> field and the tiddlers' <<.field list-before>> and <<.field list-after>> fields.
|
The output is [[sorted|Order of Tagged Tiddlers]] using the tag's <<.field list>> field and the tiddlers' <<.field list-before>> and <<.field list-after>> fields.
|
||||||
|
|
||||||
If <<.place T>> is empty, the output of `tag` is empty, and the output of `!tag` is a copy of the input.
|
The behaviour when <<.place T>> is empty depends on the settings of the <<.place S>> optional suffix:
|
||||||
|
|
||||||
|
* if <<.place T>> is missing and <<.place S>> is either missing or set to "loose", then the output of `tag` is empty, and the output of `!tag` is a copy of the input.
|
||||||
|
* <<.from-version "5.1.14">> if <<.place T>> is missing and <<.place S>> is set to "strict", then the output of both `tag` and `!tag` is a copy of the input
|
||||||
|
|
||||||
<<.operator-examples "tag">>
|
<<.operator-examples "tag">>
|
||||||
|
Loading…
Reference in New Issue
Block a user