Is it possible to list all external links for the current tiddler? I have no real idea on how to do this. If anyone could point me in the right direction, that would be awesome.
Thanks
Is it possible to list all external links for the current tiddler? I have no real idea on how to do this. If anyone could point me in the right direction, that would be awesome.
Thanks
Hi @tcoopman , what do you mean by external links? Do you mean all tiddlers that link to the current one?
That would be easily doable by
<$list filter="[all[current]backlinks[]]">
</$list>
or
{{{ [all[current]backlinks[]] }}}
Ah, no, sorry I wasn’t clear. I meant all urls to the web. So external as in, not to an other tiddler.
Ah ok, so you have more external links in a tiddler and would like to list them?
Yes, it’s kinda like having a list of footnotes from one tiddler. But not with footnotes but with links.
It would help if you illustrate how these links are placed in your text.
If you are using a consistent method it may be simpler.
I think we’ll have to add some javascript to do this. I’ve attached a .json
that contains two tiddlers. You should try it in an empty wiki first. It adds the extlinks[]
filter
You could do something like creating a tiddler tagged $:/tags/ViewTemplate
and adding the following to it:
\define make-ext-link()
[ext[$(currentTiddler)$]]
\end
<$list filter="[all[current]extlinks[]]">
<$wikify name="extlink" text=<<make-ext-link>>>
<<extlink>>
</$wikify>
</$list>
Then in another tiddler where you have text and external links it should show the external links listed at the bottom
But really, try this in an empty wiki first
tiddlers.json (2.6 KB)
My idea here, is I think “all links resolve to a html a tag”. If one wikifies the current tiddler into html then searches the HTM and extracts all the “a” tags, you get the list of links.
@BurningTreeC this works like a charm! and this is very useful!
Why TW Core has not such a feature?
I may recommend to add this a part of TW 5.2 core!
Hi @Mohammad ,
I’ve experienced, that a feature should be used by the core to be included to the core
So what we would have to do now is to gather ideas how this could be used in the core
What comes to my mind would be a special ViewTemplate that shows footnotes (for example)
There are some use cases like
So, ability to simply get the extlinks like links, backlings, tag, … is absolutely useful!
By the way I agree to get some more feedback from user community before asking to add this feature to core!
A minor comment: Testing in https:/tiddlywiki.com returns results like ##heading-01
or file://
See for example Anchor Links using HTML
tiddler.
Is there a way to validate the link before listing? An option maybe?
Thank you, this works perfectly and it’s exactly what I needed!
Yes that was my first tough too, I came up with this :
<$wikify name=text text={{TiddlerWithLinks}} output=html >
<$list filter="[<text>splitregexp[<a.*?>]butfirst[1]join[]]" variable=item>
<<list-links "[<item>splitregexp[</a>]butlast[1]]">>
</$list>
</$wikify>
Which is a modification of the macro found here : RegExp in Tiddlywiki — working with regexp. Rev 0.9
The issue is that with that you only get what’s inside of the <a>
tags, so to get the href too we need a different regex expression. I think this is definitively possible with wikitext only but the js solution seems much more convenient !
@telumire maybe the following code better works
<$tiddler tiddler="TiddlerWithLinks">
<$vars pattern="\b((?:https?|ftp|file)://)">
<$list filter="[<currentTiddler>get[text]split[ ]!is[blank]regexp<pattern>]">
<<currentTiddler>><br>
</$list>
</$vars>
</$tiddler>
Here TiddlerWithLinks
is a test tiddlers containing links as below
This is just a post to test regex for extracting URL http://google.com, https://www.youtube.com/watch?v=dlw32af https://instagram.com/oscar/ en.wikipedia.org
Even works for www.wikipedia.de, https://de.wikipedia.org/wiki/Wikipedia:Hauptseite or any other https://en.wikipedia.org/wiki/Regular_expression url. Even comma separated www.url1.com,www.url2.com
Hello! http://127.0.0.1:8080 and file:///G:/TW/000.%20Notes/dailynotes.html my file [[https://yahoo.com]]
The above code can handle almost all ordinary cases !
Still there are drawbacks: