Exploring default tiddler links hackability in V5.3.0

Thanks @btheado for trouble shooting this;

  • This was speculation but if we are to provide “default tiddler links hackability” would it make more sense to place it in the core?

I am revisiting this today to try and crystallise the result of this thread into a solution, with tags driving before and after default link hackability.

I think the $remappable attribute of the GenesisWidget is as of yet undocumented. What does it do?

Thank you @TW_Tones and thank you @btheado for this nice example.

Yes please! This example shows an applied and useful scenario of custom widget, genesis widget and parameters widget.

It also shows how wonderful can be the new features of TW 5.3.0.

Thanks @Yaisog that’s an oversight. I’ll push a docs update when I am back at my desk.

The $remappable attribute controls whether the genesis widget honours custom overrides. It defaults to yes which means that any custom redefinition of the target widget will be honoured as usual. Set it to no to ignore any custom redefinitions, and instead create an instance of the base widget as though it had not been redefined.

The latest prerelease now has this fix.

It was great to rediscover the examples in this thread now that I’m digging into the new 5.3.0 features. Many thanks to @btheado in particular for the tip about @params!

A question I haven’t yet managed to answer through trial and error:

I understand the use of <$slot $name=ts-raw><$text text=<<to>>/></$slot> to provide text content for constructions like <$link/>, but is it possible to redefine the text displayed when the children array is not empty?

  • As a hypothetical example: Could I redefine the widget so that [[A-Link-With-Hyphens]] displays as A Link With Hyphens?

Edit: In the interim, since I use uni-link anyway, I hacked the linkText macro (as defined in $:/plugins/wikilabs/uni-link/uni-link-macro) to conditionally display alternate text, and that works just fine for my purposes. If there’s a way to do this with “vanilla” 5.3.0, I’d still like to hear it, though!

Yes. It isn’t as easy but it can be done. The $parseTreeNodes attribute on the parameters widget gives access to the children array and the jsonindexes and jsonget operators can be used to get the content:

\widget $link()
\whitespace trim
<!-- Use a parameters widget so we can use `$params` to define a variable
 containing all the passed-in parameters -->
<$parameters to=<<currentTiddler>> tiddler="" $params="@params" $parseTreeNodes=@ptn>
<$genesis
  $type="$link"
  $remappable="no"
  $names="[<@params>jsonindexes[]]"
  $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]">
<$list
  emptyMessage="<$slot $name=ts-raw><$text text=<<to>>/></$slot>"
  filter="[<@ptn>jsonindexes[]] :map[<@ptn>jsonget<currentTiddler>,[text]] :and[regexp[-]split[-]join[ ]]">
<$text text=<<currentTiddler>>/>
</$list>
</$genesis>
</$parameters>
\end

In the above, I use the variable names @ptn to access the children. If there is a text field containing a dash, then the dashes are replaced with spaces. Otherwise it will fallback to the $slot content.

#[[A-Link-With-Hyphens]]
#<$link to="A-Link-With-Hyphens"/>
#<$link to="A-Link-With-Hyphens"></$link>
#[[some missing tiddler]]
#HelloThere
#[[link text|HelloThere]]
#<$link to="HelloThere">Some different text</$link>
#<$link/>
#<$link to="HelloThere"/>
#<$link to="HelloThere"></$link>

With the changes, the above (placed in a tiddler named “modified link widget test”) renders like this:

  1. A Link With Hyphens
  2. A-Link-With-Hyphens
  3. A-Link-With-Hyphens
  4. some missing tiddler
  5. HelloThere
  6. link text
  7. Some different text
  8. modified link widget test
  9. HelloThere
  10. HelloThere

As you can see the dashes in test case 2 and 3 are not handled. More changes would be required.

You can see the above in action using this share site link.

1 Like

I think the regexp[-] in the above :and filter run is not needed.

`:and[split[-]join[ ]]`

should work also. Is there a reason for the regexp?

Yes. The reason is that <$text text=<<currentTiddler>>/> is not perfectly backwards compatible like <$slot $name=ts-raw><$text text=<<to>>/></$slot>. Therefore I used the regexp to minimize the number of cases in which the emptyMessage is not used.

This case would be broken without the regexp, for example:

#<$link to="HelloThere"><b>Some different text</b></$link>

Since the parse tree doesn’t have a text attribute for :map[<@ptn>jsonget<currentTiddler>,[text]] to pluck out.

@TW_Tones I modified the custom link widget code shared by you in one of the earlier post to add a button next to the link to get popup preview of the tiddler - share demo

Any suggestions to modify it so that it visible only in certain places like tiddler body, recents and in advanced search results ?

1 Like

Nice application @arunnbabu81

The way it works is to redefine the link widget, and currently your wiki has this definition with the $:/tags/Macro/View/Body tag. Which should only replace its use in the tiddler body.

You could instead use $:/tags/Global for it to replace even more cases of its use.
Snag_605a5116

Or you could import it into tiddlers where you want it to apply

\import [[$:/arsheth/widget/link]]

Or since you used the $:/tags/link-suffix you could wrap the contents of that tiddler with a list that determins if it should be displayed or not

<$list filter="[all[current]is[tiddler]]" variable=~>
...
</$list>
2 Likes