diff --git a/plugins/tiddlywiki/freelinks/text.js b/plugins/tiddlywiki/freelinks/text.js index 409f40086..6769419d6 100755 --- a/plugins/tiddlywiki/freelinks/text.js +++ b/plugins/tiddlywiki/freelinks/text.js @@ -12,7 +12,9 @@ An override of the core text widget that automatically linkifies the text /*global $tw: false */ "use strict"; -var Widget = require("$:/core/modules/widgets/widget.js").widget; +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; var TextNodeWidget = function(parseTreeNode,options) { this.initialise(parseTreeNode,options); @@ -43,8 +45,8 @@ TextNodeWidget.prototype.execute = function() { type: "plain-text", text: this.getAttribute("text",this.parseTreeNode.text || "") }]; - // Only process links if not disabled - if(this.getVariable("tv-wikilinks",{defaultValue:"yes"}).trim() !== "no" && this.getVariable("tv-freelinks",{defaultValue:"no"}).trim() === "yes") { + // 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()) { // Get the information about the current tiddler titles, and construct a regexp this.tiddlerTitleInfo = this.wiki.getGlobalCache("tiddler-title-info",function() { var titles = [], @@ -122,6 +124,16 @@ TextNodeWidget.prototype.execute = function() { this.makeChildWidgets(childParseTree); }; +TextNodeWidget.prototype.isWithinButtonOrLink = function() { + var withinButtonOrLink = false, + widget = this.parentWidget; + while(!withinButtonOrLink && widget) { + withinButtonOrLink = widget instanceof ButtonWidget || widget instanceof LinkWidget; + widget = widget.parentWidget; + } + return withinButtonOrLink; +}; + /* Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering */