mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-28 15:08:46 +00:00
LinkWidget: Add support for tv-filter-export-link
This change makes it possible to perform the conversion from target tiddler title to `href` value as a filter expression (previously a JavaScript macro was needed to use the tv-get-export-link variable)
This commit is contained in:
parent
2381fb5312
commit
06ea4060cb
@ -80,14 +80,26 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
|||||||
}
|
}
|
||||||
domNode.setAttribute("class",classes.join(" "));
|
domNode.setAttribute("class",classes.join(" "));
|
||||||
// Set an href
|
// Set an href
|
||||||
|
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"),
|
var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"),
|
||||||
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$",
|
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$";
|
||||||
wikiLinkText = $tw.utils.replaceString(wikiLinkTemplate,"$uri_encoded$",encodeURIComponent(this.to));
|
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});
|
wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText});
|
||||||
if(tag === "a") {
|
if(tag === "a") {
|
||||||
domNode.setAttribute("href",wikiLinkText);
|
domNode.setAttribute("href",wikiLinkText);
|
||||||
}
|
}
|
||||||
|
// Set the tabindex
|
||||||
if(this.tabIndex) {
|
if(this.tabIndex) {
|
||||||
domNode.setAttribute("tabindex",this.tabIndex);
|
domNode.setAttribute("tabindex",this.tabIndex);
|
||||||
}
|
}
|
||||||
|
20
editions/tw5.com/tiddlers/tv-filter-export-link Variable.tid
Normal file
20
editions/tw5.com/tiddlers/tv-filter-export-link Variable.tid
Normal file
@ -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.
|
@ -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
|
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>>
|
<<.this-is-static-link-variable>>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
caption: link
|
caption: link
|
||||||
created: 20131024141900000
|
created: 20131024141900000
|
||||||
modified: 20170328172846359
|
modified: 20170828100455842
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: LinkWidget
|
title: LinkWidget
|
||||||
type: text/vnd.tiddlywiki
|
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-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
|
* `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 `<a>` 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
|
! Configuration variables
|
||||||
|
|
||||||
* <<.vlink tv-wikilinks>>
|
* <<.vlink tv-wikilinks>>
|
||||||
|
* <<.vlink tv-filter-export-link>>
|
||||||
* <<.vlink tv-wikilink-template>>
|
* <<.vlink tv-wikilink-template>>
|
||||||
* <<.vlink tv-wikilink-tooltip>>
|
* <<.vlink tv-wikilink-tooltip>>
|
||||||
* <<.vlink tv-get-export-link>>
|
* <<.vlink tv-get-export-link>>
|
||||||
|
Loading…
Reference in New Issue
Block a user