diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index 278600518..15a99ce2c 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -80,14 +80,26 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { } domNode.setAttribute("class",classes.join(" ")); // Set an href - var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"), - wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$", + var wikilinkTransformFilter = this.getVariable("tv-filter-export-link"), + wikiLinkText; + if(wikilinkTransformFilter) { + // Use the filter to construct the href + wikiLinkText = this.wiki.filterTiddlers(wikilinkTransformFilter,this,function(iterator) { + iterator(self.wiki.getTiddler(self.to),self.to) + })[0]; + } else { + // Expand the tv-wikilink-template variable to construct the href + var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"), + wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$"; wikiLinkText = $tw.utils.replaceString(wikiLinkTemplate,"$uri_encoded$",encodeURIComponent(this.to)); - wikiLinkText = $tw.utils.replaceString(wikiLinkText,"$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); + wikiLinkText = $tw.utils.replaceString(wikiLinkText,"$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); + } + // Override with the value of tv-get-export-link if defined wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText}); if(tag === "a") { domNode.setAttribute("href",wikiLinkText); } + // Set the tabindex if(this.tabIndex) { domNode.setAttribute("tabindex",this.tabIndex); } diff --git a/editions/tw5.com/tiddlers/tv-filter-export-link Variable.tid b/editions/tw5.com/tiddlers/tv-filter-export-link Variable.tid new file mode 100644 index 000000000..63d0c39f0 --- /dev/null +++ b/editions/tw5.com/tiddlers/tv-filter-export-link Variable.tid @@ -0,0 +1,20 @@ +caption: tv-filter-export-link +created: 20170828095135984 +modified: 20170828095757620 +tags: Variables [[Core Variables]] [[Configuration Variables]] +title: tv-filter-export-link Variable +type: text/vnd.tiddlywiki + +The <<.def tv-filter-export-link>> [[variable|Variables]] controls the value of the `href` attribute on the HTML `a` element generated by the <<.wlink LinkWidget>> widget. If defined, it takes precedence over the [[tv-wikilink-template Variable]]. + +<<.this-is-static-link-variable>> + +The variable is treated as a filter that is given the target tiddler title as input. The filter is evaluated and the first result is used as the `href` attribute. + +For example: + +``` +\define tv-filter-export-link() [encodeuricomponent[]encodeuricomponent[]addsuffix[.html]] +``` + +See also the <<.vlink tv-get-export-link>> variable, which dominates over this one. diff --git a/editions/tw5.com/tiddlers/variables/tv-wikilink-template.tid b/editions/tw5.com/tiddlers/variables/tv-wikilink-template.tid index 5a6ab8182..6fdac1410 100644 --- a/editions/tw5.com/tiddlers/variables/tv-wikilink-template.tid +++ b/editions/tw5.com/tiddlers/variables/tv-wikilink-template.tid @@ -1,11 +1,11 @@ -created: 20150228105954000 -modified: 20150228131300000 -title: tv-wikilink-template Variable -tags: Variables [[Core Variables]] [[Configuration Variables]] -type: text/vnd.tiddlywiki caption: tv-wikilink-template +created: 20150228105954000 +modified: 20170828095603911 +tags: Variables [[Core Variables]] [[Configuration Variables]] +title: tv-wikilink-template Variable +type: text/vnd.tiddlywiki -The <<.def tv-wikilink-template>> [[variable|Variables]] controls the value of the `href` attribute on the HTML `a` element generated by the <<.wlink LinkWidget>> widget. +The <<.def tv-wikilink-template>> [[variable|Variables]] controls the value of the `href` attribute on the HTML `a` element generated by the <<.wlink LinkWidget>> widget. The <<.vlink tv-filter-export-link>>, if defined, it takes precedence over the <<.vlink tv-wikilink-template>> variable. <<.this-is-static-link-variable>> diff --git a/editions/tw5.com/tiddlers/widgets/LinkWidget.tid b/editions/tw5.com/tiddlers/widgets/LinkWidget.tid index 0b5dc0c66..770ab0f1b 100644 --- a/editions/tw5.com/tiddlers/widgets/LinkWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/LinkWidget.tid @@ -1,6 +1,6 @@ caption: link created: 20131024141900000 -modified: 20170328172846359 +modified: 20170828100455842 tags: Widgets title: LinkWidget type: text/vnd.tiddlywiki @@ -60,9 +60,20 @@ This causes the tooltip to be the ''tooltip'' field of the target tiddler. If th * `tc-tiddlylink-missing` - applied to tiddler links where the target tiddler doesn't exist * `tc-tiddlylink-resolves` - applied to tiddler links when the target tiddler does exist +! `href` generation + +The following process is used to generate the `href` attribute of the generated HTML `` element: + +# If <<.vlink tv-get-export-link>> is defined it is invoked to convert the target tiddler title to the `href` value +#* In practice, only a [[JavaScript macro|Macros]] can be used +# If <<.vlink tv-filter-export-link>> is defined it is interpreted as a filter that converts the target tiddler title to the `href` value +# If <<.vlink tv-wikilink-template>> is defined it is treated as a specialised macro body that can perform limited conversion of the target tiddler title to the `href` value +# Otherwise, the target tiddler title is URI encoded to create the `href` + ! Configuration variables * <<.vlink tv-wikilinks>> +* <<.vlink tv-filter-export-link>> * <<.vlink tv-wikilink-template>> * <<.vlink tv-wikilink-tooltip>> * <<.vlink tv-get-export-link>>