From 0ed32fded996826a59832d7a7555bb16c4a57864 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sat, 13 Feb 2021 12:03:35 +0000 Subject: [PATCH] Freelinks: Add a filter for which tiddlers can be the targets of freelinks --- plugins/tiddlywiki/freelinks/settings.tid | 2 ++ plugins/tiddlywiki/freelinks/text.js | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/tiddlywiki/freelinks/settings.tid b/plugins/tiddlywiki/freelinks/settings.tid index 844eb1d26..dc4577ab7 100644 --- a/plugins/tiddlywiki/freelinks/settings.tid +++ b/plugins/tiddlywiki/freelinks/settings.tid @@ -1,5 +1,7 @@ title: $:/plugins/tiddlywiki/freelinks/settings +Filter defining tiddlers to which freelinks are made: <$edit-text tiddler="$:/config/Freelinks/TargetFilter" tag="input" placeholder="Filter expression..." default=""/> + <$checkbox tiddler="$:/config/Freelinks/Enable" field="text" checked="yes" unchecked="no" default="no"> <$link to="$:/config/Freelinks/Enable">Enable freelinking within tiddler view templates <$checkbox tiddler="$:/config/Freelinks/IgnoreCase" field="text" checked="yes" unchecked="no" default="no"> <$link to="$:/config/Freelinks/IgnoreCase">Ignore case diff --git a/plugins/tiddlywiki/freelinks/text.js b/plugins/tiddlywiki/freelinks/text.js index 867eb030a..b11eb0ef5 100755 --- a/plugins/tiddlywiki/freelinks/text.js +++ b/plugins/tiddlywiki/freelinks/text.js @@ -12,6 +12,8 @@ An override of the core text widget that automatically linkifies the text /*global $tw: false */ "use strict"; +var TITLE_TARGET_FILTER = "$:/config/Freelinks/TargetFilter"; + var Widget = require("$:/core/modules/widgets/widget.js").widget, LinkWidget = require("$:/core/modules/widgets/link.js").link, ButtonWidget = require("$:/core/modules/widgets/button.js").button, @@ -51,7 +53,9 @@ TextNodeWidget.prototype.execute = function() { if(this.getVariable("tv-wikilinks",{defaultValue:"yes"}).trim() !== "no" && this.getVariable("tv-freelinks",{defaultValue:"no"}).trim() === "yes" && !this.isWithinButtonOrLink()) { // Get the information about the current tiddler titles, and construct a regexp this.tiddlerTitleInfo = this.wiki.getGlobalCache("tiddler-title-info-" + (ignoreCase ? "insensitive" : "sensitive"),function() { - var sortedTitles = self.wiki.allTitles().sort(function(a,b) { + var targetFilterText = self.wiki.getTiddlerText(TITLE_TARGET_FILTER), + titles = !!targetFilterText ? self.wiki.filterTiddlers(targetFilterText,$tw.rootWidget) : self.wiki.allTitles(), + sortedTitles = titles.sort(function(a,b) { var lenA = a.length, lenB = b.length; // First sort by length, so longer titles are first