@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).
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.
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…
I will have to test but what happens if there is no |.
I did discover that technicaly most widgets accept various inputs and output something. Most of the time no further processing is done on a widgets output. This makes a custom widget that uses something similar to your code to list all links with pretty links when available a good idea. We could also add logic to aquire the caption as the prety link if no pretty link is given.
That depends entirely on your desired output. Since I didn’t know your intended use-case, I left that as an exercise for you. But for instance, if you wanted to retrieve a list of hard links (pretty and otherwise), you can test this on tw-com:
For this example, I changed the caption of HelloThere to caption: {{$:/core/icon}} Hello There to demonstrate the way it works with an alternate field (which may itself contain wikitext, like the icon).
I also used <$list filter="[link.display<field>]">{{!!title}}</$list> rather than <$transclude $variable=link.display field=<<field>> /> to ensure that any wikitext present in the field is parsed correctly (not simply displayed as raw text).
Revised in my code above but not in the screenshot:
Keep \function get.links outside the display procedure so it can be used in other filter contexts.
Of course, I’m not entirely sure why you would want to do this, as pretty-links are typically chosen to make sense in context, and lose that context if collected elsewhere. But it’s certainly possible!
This feels a little over-complicated to me, but as I said, I don’t know your use-case. Do you see a benefit to using a widget over a procedure? How do you envision using it?
To clarify is we now have a simple set of operators like links and backlinks to the recent backtranscludes that do retrieve links to related tiddlers. In such cases the pretty link is not available even when provided, or we need to seperatly retrieve the caption if this is in use.
Primarily I would like to see this gap filled
You have detailed a solution for the links operator
You have proposed returning a compound value using | as a delimiter.
What practical use do I have?
First in my view addressing a systemic gap in in TiddlyWiki that we could fill.
Second be able to list all links found in a tiddler (links[]) in a summary or footer on a tiddler;
but maintaining the pretty link if provided
Doing similar for other related link operators like backlinks.
Keep it simple Sweetheart
Using the method suggested by @etardiff Emily and simply wrapping the pretty|title or title in [[ ]] will allow listing of links[] with their original pretty title.
Similarly sometime we may want to find caption|title
or even pretty|title else caption|title else title
The general pattern here is retriving the display|title then subsequently returning [[display|title]] or [[title]], this is an example of (sometimes) returning two values from filters, not only a single value.
If we adopt some functions or widgets that return display|title or title and then a general solution for handling these eg wrap and display with the pretty link whern available.
Widgets tend to be where data goes to be displayed, so if we want a generic solution to accept display with space|title or display|title or title (and lists there of) and return [[display|title]] or [[title]] a widget makes sense.
So if we build an ecosystem of tools to take account of pretty links and captions as links to titles we will generate one or more display|title or title items, an display them at the end point with a widget and / or function.
Without complicating the above notes, as pointed out by @etardiff perhaps we need to also consider the form icon|display|title or a variation there of.
The author of the content may use a pretty link or want the caption to be used in various contexts otherwise they may not have used a pretty link or caption.
Final note:
We have also found value in leveraging the missing tiddler mechanisium for virtual titles, and of course these can also optionaly have pretty links which it would be helpfull if they too were available to the designer.
I also not the observation that table rows using WikiText are | delimited including a leading and trailing | so any tools designed to handle the aformentioned | handling, may be designed to assist in extracting a row from text as well.