Using links[] in current tiddler

Did you know the following will collect most links embeded within the tiddler text field and list them?

<$list filter="[all[current]links[]]">

</$list>

Adding this to the view template gives you summary of all links in a tiddler seperate from the text.

  • It will only return the effective title and ignore any prettl links like [[new name|long tiddlername]]

Question

Is there a simple, or mor complex way we can extract these links and also have access to the pretty name of each link?

Why do I ask?

Because we could use a naming standard in a pretty link such as f1 f2 etc… and use this to handle links selectivly based on this pretty link.

  • perhaps we could build an alternate operator that returned the original link eg [[f1|long tiddler name]] instead such as [prettylinks[]]
  • In this case it will return the full text string of the link not a reduced one.
  • Perhaps a clone of the existing link operator modified any JavaScriptors should see $:/core/modules/filters/links.js for a small project.
  • But could this also be valid for backlinks and other operators?

I wont spell it out here but I can imagin this opening a whole lot of interesting tricks if we had such a mechanisium.

1 Like

@TW_Tones i think I could use this. I’ll add to my todo list to review.

I recently created a tiddler in my project to list “referenced images”. Kind of the same idea, I think. My tiddler uses a regular expression to determine img tags within in user selected field. I don’t think a regular expression will work here.

Link to “Referenced Inages”

Ideally, I would want something that returns both the link (the tiddler referenced) and the display text (if found).

Thanks for your responce

Actually if you think about it there is already a regular expression doing exactly this, the core detects [[title]] and [[pretty|title]] already and in the final render replaces it with references to the $link widget, this includes camelCase if configured.

I raise this because it points to an existing limitation with filter operators dealing with links, in so far as they can only return the title and the pretty link if used is lost. If we think about it they currently return the [[title]] or a title formatted list, it seems to me modified or new filter operators could return [[pretty|title]] there by;

  • Retain the pretty name
  • Allow other wikiscript to interrogate the prefix eg [[pretty| and further filter based on that.
  • In a way we simply want to force the operator to return the [[ ]] and the pretty| of such links.

In one way I am simply asking that link related operators include a mode that returns titles in there as found form.

  • Of course we could expand this to include returning the fill text of other link forms as found [img[ etc…
  • As a result it may suggest one or more new operators with this specific objective in mind.

I don’t think you really need a JS operator for this; you can do it with a function. For example:

\function get.links(lb:"[[", rb:"]]") [get[text]split<lb>search<rb>] :map[split<rb>first[]]

{{{ [[HelloThere]get.links[]] }}}

Results on TW-com:

non-linear|Philosophy of Tiddlers
capturing|Creating and editing tiddlers
organising|Structuring TiddlyWiki
sharing|Sharing your tiddlers with others
to-do list|TaskManagementExample
essay or novel|"TiddlyWiki for Scholars" by Alberto Molina
still be able to use|Future Proof

You could then split on | for whatever further processing you wanted to do.

I hard-coded get[text] into the function to parallel links[], which only works with the text field (to my frequent frustration). But you could obviously replace it with a parameter, which would probably be my preference…

\function get.links(field:"text", lb:"[[", rb:"]]") [get<field>split<lb>search<rb>] :map[split<rb>first[]]

{{{ [[HelloThere]get.links[]] }}}
{{{ [[HelloThere]get.links[my-field]] }}}

Or just leave it out of the function altogether and handle that in the filter where you’re using it:

\function get.links(lb:"[[", rb:"]]") [split<lb>search<rb>] :map[split<rb>first[]]

{{{ [{HelloThere}get.links[]] }}}
{{{ [{!!text}get.links[]] }}}
{{{ [<storyTiddler>get[my-field]get.links[]] }}}