Forcing CamelCase links to show as caption/subtitle

So I found an alleged solution HERE however I can’t seem to make it work the way I’m thinking?

Basically, I’m using my tiddlywiki to host all of my ttrpg material for my players. There are a ton of NPCs (non-player characters) and a ton of information in general, all of it linking to other tiddlers in one way or another. When I need to link a tiddler, I like the efficiency of using camelcase links, but they are ugly and can be hard to read potentially. When I use a camelcase link, I want it to show as the linked tiddler’s caption/subtitle.

Example:
I have a Tiddler called AugustisLarkin. The caption is Augustus Larkin.

I have another Tiddler called JacksonElias. In the body of that tiddler, I have a note:

  • Met AugustusLarkin in Lima, Peru

I want AugustusLarkin to, of course, link to that tiddler, but in JacksonElias tiddler I want it to show as:

  • Met Augustus Larkin in Lima, Peru

Any help would be greatly appreciated!

Welcome to the forum!

Do you mean like this?

[[This is a link]]

I’m not sure?

When I use a camelcase link in a tiddler (like AugustusLarkin), I want the link to show as Augustus Larken. So I want to be able to use camelcase to do the linking, but when I save the tiddler, I want the link to show with a space instead of as camelcase.

It’s certainly possible to change the way links display by default, but (without really looking into it) I suspect it may be more difficult to change the behavior of CamelCase links and only CamelCase links.

If you don’t mind the default-to-caption behavior for all your links, try dragging this tiddler into your wiki (code courtesy of @intrinsical in this thread): CaptionLinks.json (632 Bytes).

  • Links to tiddlers that lack a caption field will fall back to using the title instead.
  • By default, this will affect all the links in your wiki (including links in your Open tab, etc.) If you’d like to limit it to links in the tiddler body only, you can replace the $:/tags/Global tag with $:/tags/Global/View/Body.
1 Like

So, I tried that, but it still doesn’t seem to work on camelcase links. Heres my wiki so you can see: https://masks-draft.tiddlyhost.com/

You can see the camelcase link in the default tiddler (an overview of…etc). It links to the note and the tiddler itself shows the caption as the title, but the link down not appear as the caption…

That’s odd! Are you sure you imported the file I shared and saved afterwards? I just tested it myself and it seems to work as I’d expect: image

… I’m a dummy. I did not save and refresh. The effects have now taken place. Thank you!

1 Like

Just for completeness, the camelCase links use the $link widget behind the scenes and there are ways to redefine it. But if you are happy now perhaps don’t bother using this approach.

This was the solution I suggested (though I didn’t repost the raw code here, so that’s on me.) Here’s the text of the tiddler I shared:

\widget $link(to)
\whitespace trim
<$parameters to=<<currentTiddler>> tiddler=<<storyTiddler>> $params="@params">
  <$genesis $type="$link" $remappable="no" $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>]" class=<<class>> >
   <$view format="text" field="caption" tiddler=<<to>>>
    <$slot $name=ts-raw><$text text=<<to>> /></$slot>
   </$view>
  </$genesis>
</$parameters> 
\end

As a general note for Savannah or anyone else interested in overriding link behavior: the bulk of this tiddler is simply recreating the default $link widget. Here’s the part that selects the caption first, if available:

<$view format="text" field="caption" tiddler=<<to>>>
    <$slot $name=ts-raw><$text text=<<to>> /></$slot>
</$view>

Like the $transclude widget, $view ignores its content unless the field it specifies is missing or empty. In this case, if the tiddler being linked to doesn’t have a caption, the link will revert to its default behavior and display the title instead—identified here with <$slot $name=ts-raw><$text text=<<to>> /></$slot>.

I’m not sure whether it’s possible to redefine $link in a way that only affects CamelCase links, though, and I’d tend to assume it’s not, as CamelCase and [[CamelCase]] look identical in the parse- and widget-trees. If anyone has more insight on that front, I hope they’ll weigh in!

2 Likes