mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Fix case-insensitive freelinks
This commit is contained in:
parent
7ee9003df7
commit
c9692d7a50
@ -9,7 +9,7 @@ Freelinking is activated for runs of text that have the following variables set:
|
|||||||
* `tv-wikilinks` is NOT equal to `no`
|
* `tv-wikilinks` is NOT equal to `no`
|
||||||
* `tv-freelinks` is set to `yes`
|
* `tv-freelinks` is set to `yes`
|
||||||
|
|
||||||
Freelinks are case sensitive.
|
Freelinks are case sensitive by default but can be configured to ignore case in the settings tab.
|
||||||
|
|
||||||
Within view templates, the variable `tv-freelinks` is automatically set to the content of $:/config/Freelinks/Enable, which can be set via the settings panel of this plugin.
|
Within view templates, the variable `tv-freelinks` is automatically set to the content of $:/config/Freelinks/Enable, which can be set via the settings panel of this plugin.
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ TextNodeWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
Compute the internal state of the widget
|
Compute the internal state of the widget
|
||||||
*/
|
*/
|
||||||
TextNodeWidget.prototype.execute = function() {
|
TextNodeWidget.prototype.execute = function() {
|
||||||
var self = this;
|
var self = this,
|
||||||
|
ignoreCase = self.getVariable("tv-freelinks-ignore-case",{defaultValue:"no"}).trim() === "yes";
|
||||||
// Get our parameters
|
// Get our parameters
|
||||||
var childParseTree = [{
|
var childParseTree = [{
|
||||||
type: "plain-text",
|
type: "plain-text",
|
||||||
@ -49,10 +50,8 @@ TextNodeWidget.prototype.execute = function() {
|
|||||||
// Only process links if not disabled and we're not within a button or link widget
|
// Only process links if not disabled and we're not within a button or link widget
|
||||||
if(this.getVariable("tv-wikilinks",{defaultValue:"yes"}).trim() !== "no" && this.getVariable("tv-freelinks",{defaultValue:"no"}).trim() === "yes" && !this.isWithinButtonOrLink()) {
|
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
|
// Get the information about the current tiddler titles, and construct a regexp
|
||||||
this.tiddlerTitleInfo = this.wiki.getGlobalCache("tiddler-title-info",function() {
|
this.tiddlerTitleInfo = this.wiki.getGlobalCache("tiddler-title-info-" + (ignoreCase ? "insensitive" : "sensitive"),function() {
|
||||||
var titles = [],
|
var sortedTitles = self.wiki.allTitles().sort(function(a,b) {
|
||||||
reparts = [],
|
|
||||||
sortedTitles = self.wiki.allTitles().sort(function(a,b) {
|
|
||||||
var lenA = a.length,
|
var lenA = a.length,
|
||||||
lenB = b.length;
|
lenB = b.length;
|
||||||
// First sort by length, so longer titles are first
|
// First sort by length, so longer titles are first
|
||||||
@ -72,14 +71,15 @@ TextNodeWidget.prototype.execute = function() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
titles = [],
|
||||||
|
reparts = [];
|
||||||
$tw.utils.each(sortedTitles,function(title) {
|
$tw.utils.each(sortedTitles,function(title) {
|
||||||
if(title.substring(0,3) !== "$:/") {
|
if(title.substring(0,3) !== "$:/") {
|
||||||
titles.push(title);
|
titles.push(title);
|
||||||
reparts.push("(\\b" + $tw.utils.escapeRegExp(title) + "\\b)");
|
reparts.push("(\\b" + $tw.utils.escapeRegExp(title) + "\\b)");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var ignoreCase = self.getVariable("tv-freelinks-ignore-case",{defaultValue:"no"}).trim() === "yes";
|
|
||||||
return {
|
return {
|
||||||
titles: titles,
|
titles: titles,
|
||||||
regexp: new RegExp(reparts.join("|"),ignoreCase ? "i" : "")
|
regexp: new RegExp(reparts.join("|"),ignoreCase ? "i" : "")
|
||||||
@ -102,7 +102,7 @@ TextNodeWidget.prototype.execute = function() {
|
|||||||
childParseTree[index] = {
|
childParseTree[index] = {
|
||||||
type: "link",
|
type: "link",
|
||||||
attributes: {
|
attributes: {
|
||||||
to: {type: "string", value: match[0]},
|
to: {type: "string", value: ignoreCase ? this.tiddlerTitleInfo.titles[match.indexOf(match[0],1) - 1] : match[0]},
|
||||||
"class": {type: "string", value: "tc-freelink"}
|
"class": {type: "string", value: "tc-freelink"}
|
||||||
},
|
},
|
||||||
children: [{
|
children: [{
|
||||||
@ -145,7 +145,7 @@ TextNodeWidget.prototype.refresh = function(changedTiddlers) {
|
|||||||
titlesHaveChanged = false;
|
titlesHaveChanged = false;
|
||||||
$tw.utils.each(changedTiddlers,function(change,title) {
|
$tw.utils.each(changedTiddlers,function(change,title) {
|
||||||
if(change.isDeleted) {
|
if(change.isDeleted) {
|
||||||
titlesHaveChanged = true
|
titlesHaveChanged = true;
|
||||||
} else {
|
} else {
|
||||||
titlesHaveChanged = titlesHaveChanged || !self.tiddlerTitleInfo || self.tiddlerTitleInfo.titles.indexOf(title) === -1;
|
titlesHaveChanged = titlesHaveChanged || !self.tiddlerTitleInfo || self.tiddlerTitleInfo.titles.indexOf(title) === -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user