diff --git a/core/modules/filters/annotatedbacklinks.js b/core/modules/filters/annotatedbacklinks.js new file mode 100644 index 000000000..1d89270c9 --- /dev/null +++ b/core/modules/filters/annotatedbacklinks.js @@ -0,0 +1,46 @@ +/*\ +title: $:/core/modules/filters/annotatedbacklinks.js +type: application/javascript +module-type: filteroperator + +Filter operator for returning all the back links from a tiddler with a given annotation + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +function parseAnnotations(annotationstring){ + var annotations = {} + if (annotationstring.length > 0){ + annotationstring.split(',').forEach(function(part){ + if (part.includes('=')){ + let subparts = part.split('=', 2); + let key = subparts[0], + value = subparts[1]; + annotations[key] = value; + }else{ + annotations[part] = "*"; + } + }); + } + return annotations; +} + +/* +Export our filter function +*/ +exports.annotatedbacklinks = function(source,operator,options) { + var results = new $tw.utils.LinkedList(); + source(function(tiddler,title) { + var annotations = parseAnnotations(operator.operands[0]); + console.log(annotations); + results.pushTop(options.wiki.getTiddlerAnnotatedBacklinks(title, annotations)); + }); + return results.makeTiddlerIterator(options.wiki); +}; + + +})(); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 4c8e70772..deb37597c 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -585,6 +585,7 @@ exports.extractAnnotatedLinks = function(parseTreeRoot, annotations) { checkParseTree = function(parseTree) { for(var t=0; t