Find backlinks inside a macrocall

136 views
Skip to first unread message

kebi

unread,
Aug 18, 2020, 12:47:36 AM8/18/20
to tiddl...@googlegroups.com
Hello guys,
I want to know how to detect a backlink inside a macrocall, since the default
all[current]backlinks[]]
doesn't detect them.

This is my macrocall:
<$macrocall $name="remembercz" text="[[example backlink]]"/>

I tried doing this

\define text-pattern()
[[$(currentTiddler)$]]
\end

<$list filter="[all[current]backlinks[]] [regexp:title<text-pattern>] -[is[current]] -[tag[hide]] -[is[system]]"></$list>

but it didn't work.

Any ideas on how can I detect the backlink inside a macrocall with a filter?

TW Tones

unread,
Aug 18, 2020, 3:05:00 AM8/18/20
to TiddlyWiki
kebi

Unless you set the current tiddler inside a macro call it will be the "current tiddler". So it is not clear what you want here,

If you have a listWidget and don't use the variable=varname the currentTiddler is changed for each item resulting from the list filter.

In your example [all[current]backlinks[]] eg `{{{ [all[current]backlinks[]] }}}` returns all tiddlers that link back to the currentTiddler.
`[regexp:title<text-pattern>]` is looking in each baclink tiddler for the exact string of the current tiddler title with square brackets. But there is no need because that is what backlinks are (and also include camelCase words)?

-[is[current]] backlinks excluding back links to self in self?
-[tag[hide]] from backlinks exclude tiddlers with a backlink to here with the hide tag
-[is[system]] from backlinks  exclude system tiddlers that back link to currentTiddler

More info please.

Regards
Tony

harut...@gmail.com

unread,
Aug 18, 2020, 5:05:26 AM8/18/20
to TiddlyWiki
Tony thanks for your message,

what I was trying to say is that

[all[current]backlinks[]]

doesn't return the backlinks wrote inside a macrocall, like this one:

<$macrocall $name="remembercz" text="[[example backlink]]"/>

To fix that issue I wanted to create a filter that searches for titles written inside [[]], so that it works inside macrocalls aswell.
The problem is that you can't use [[]] brackets inside a macro definition, so my first attempt to accomplish this didn't work:

\define text-pattern()
[[$(currentTiddler)$]]
\end

<$list filter="[all[current]backlinks[]] [regexp:title<text-pattern>]"></$list>

So basically I want to know if there is another way I can create a filter that searches for the string "[[example backlink]]" to find
backlinks inside a macrocall.

Regards,
kebi

TW Tones

unread,
Aug 18, 2020, 9:13:45 AM8/18/20
to TiddlyWiki
Kebi

I will look again tomorrow however it is still not clear what you want to do and your example is not complete.

Without any wiki text can you say what you want?

backlinks can only be found for a tiddler when other have links to it.

What do you mean when you say in a Macrocall?

what do you want the macro to do?

why a macro and not just in a list filter?

best wishes tones

Eric Shulman

unread,
Aug 18, 2020, 9:50:14 AM8/18/20
to tiddl...@googlegroups.com
On Tuesday, August 18, 2020 at 2:05:26 AM UTC-7, harut...@gmail.com wrote:
[all[current]backlinks[]]
doesn't return the backlinks wrote inside a macrocall, like this one:
<$macrocall $name="remembercz" text="[[example backlink]]"/>
To fix that issue I wanted to create a filter that searches for titles written inside [[]], so that it works inside macrocalls aswell.
The problem is that you can't use [[]] brackets inside a macro definition, so my first attempt to accomplish this didn't work:
\define text-pattern() [[$(currentTiddler)$]]

<$list filter="[all[current]backlinks[]] [regexp:title<text-pattern>]"></$list>

..a filter that searches for the string "[[example backlink]]"...

There are several problems with the above approach:
1) The filter you used doesn't search the *content* of the tiddler.  Rather, it is searching in the *title* of the tiddler.
2) The square brackets are actually regexp syntax.
3) The regexp filter doesn't return the matching text.  Rather, it returns the title of the tiddler in which the match was found.

Try this instead:
\define start() "[[
\define end() ]]"
<$list filter="[{!!text}split<start>splitbefore<end>removesuffix<end>]">
  <$link><<currentTiddler>></$link><br>
</$list>

<$macrocall $name="remembercz" text="[[example backlink]]"/>

1) The start and end macros only find quoted links that have doubled-square brackets around them
2) The filter isolates the text in between the start and end values and then outputs that text as a link

-e




kebi

unread,
Aug 18, 2020, 7:43:15 PM8/18/20
to tiddl...@googlegroups.com
Tony,
without any wikitext what I'm trying to accomplish is to have a filter that returns the title of a tiddler that contains a backlink with [[ ]] brackets, without using the default filter for backlinks, because it doesn't work with text inside a macrocall (and I need to have text and backlinks inside the macrocall because I'm using the plugin TiddlyRemember)

kebi

unread,
Aug 18, 2020, 7:44:56 PM8/18/20
to tiddl...@googlegroups.com
Thanks Eric your code worked!

But what if I wanted to return just the title of the tiddler where the backlink was found, how can I do it??

- kebi

TW Tones

unread,
Aug 18, 2020, 8:13:59 PM8/18/20
to TiddlyWiki
Kebi,

I feel you making a conclusion at the beginning, of the statement of your problem that is incorrect.
  • Without any wikitext ? This is how tiddlywiki works?
I have tested the below code on tiddlywiki.com inside the tiddler HelloThere

Perhaps some additional info will help
{{{ [all[current]backlinks[]] }}}
This is a quick way to display backlinks in the current tiddler using the triple braces

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

</$list>
This also lists each of the backlinks, inside the list widget the current tiddler is changing to each tiddler with a backlink. 
  • Notice how the result is a list of links? No need to see it as "[[tiddleranme]]" it is treated as such already!
If you want to use a filter in a macrocall pass it as a parameter or hard code it in the macro

\define my-backlinks(filter) {{{ $filter$ }}}
<<my-backlinks "[all[current]backlinks[]]">>
or
<$macrocall $name=my-backlinks filter="[all[current]backlinks[]]"/>

Or
\define my-backlinks2(filter)
<$list filter="$filter$">

</$list>
\end
<$macrocall $name=my-backlinks2 filter="[all[current]backlinks[]]"/
>

Since the above macros operate on the current tiddler we can use the list of backlinks to get the back links for each tiddler (that is a backlink)

\define my-backlinks(filter) {{{ $filter$ }}}
\define my-backlinks3(filter)
<$list filter="$filter$">
 
Backlinks here <<currentTiddler>><br>
 
Backlinks there <<my-backlinks "[all[current]backlinks[]]">>
</$list>\end
<$macrocall $name=my-backlinks2 filter="[all[current]backlinks[]]"/>


\define my-backlinks(filter) {{{ $filter$ }}}
\define my-backlinks3(filter)
<$list filter="$filter$">
 
Backlinks here <<currentTiddler>><br>
 
Backlinks there <<my-backlinks "$filter$">>
</$list>
\end
<$macrocall $name=my-backlinks3 filter="[all[current]backlinks[]]"/
>
You will notice some tiddlers listed do not behave as links, because they have spaces etc...

\define my-backlinks4(filter)
<$list filter="$filter$">
   
<$link/>
</$list>
\end
\define my-backlinks3(filter)
<$list filter="$filter$">
  Backlinks to here <$link/
><br>
 
Backlinks to there <<my-backlinks4 "$filter$">><br>
</$list>
\end
<$macrocall $name=my-backlinks3 filter="[all[current]backlinks[]]"/
>

Regards
Tony

kebi

unread,
Aug 18, 2020, 8:36:50 PM8/18/20
to TiddlyWiki
Thanks Tony for your message,

However I think you misunderstood my request. I don't need to write filters inside a macrocall, I need a filter that returns the title of tiddlers that have backlinks inside a macrocall.

The code that Eric provided returns what I was requesting but without the title of the tiddler.

- kebi

TW Tones

unread,
Aug 18, 2020, 8:58:18 PM8/18/20
to TiddlyWiki
Kebi,

Sorry, I m doing my best to help, and with what you are asking is obscure or I am a not thinking clearly?

In this case since I really have trouble understanding you question, and I go the impression Eric also misunderstood the question, I have flooded you with mechanisms relating to backlinks.

<$list filter="[all[tiddlers]backlinks[]sort[]]">

</$list>
This lists the title of all tiddlers containing backlinks without showing them

\define macroname()
<$list filter="[all[tiddlers]backlinks[]sort[]]">

</$list>
\end
<<macroname>>
This lists the title of all tiddlers containing backlinks without showing them in a macro

Or are you looking for backlinks only defined inside macros?

\define macroname()
[[This backlinks to another tiddler]]
\end
But this is not necessarily a back link, it could just be a link to a missing tiddler

I am sure I can answer question, as Eric can but it needs to be clearer. 

  • If I may respectfully suggest don't simplify the question too much. 
Regards
Tones

harut...@gmail.com

unread,
Aug 18, 2020, 10:07:30 PM8/18/20
to TiddlyWiki
When using TiddlyRemember I constantly have to write text inside macrocalls in order to create cards to be synced with an external program.
So my tiddlers will only contain macrocalls, and inside their text field goes all my notes and backlinks, like this:

<$macrocall $name="remembercz" text="card 1, here I write all my notes" />
<$macrocall $name="remembercz" text="card 2, notes with [[backlink]]" />
<$macrocall $name="remembercz" text="card 3, more notes" />

The default filter for backlinks

all[current]backlinks[]]

doesn't detect backlinks inside "text", that's why I need a filter that searches for strings inside [[ ]] brackets.

All I need is basically just a filter to use instead of

all[current]backlinks[]]

that detects backlinks inside the "text" field.

- kebi

kebi

unread,
Aug 18, 2020, 10:35:07 PM8/18/20
to TiddlyWiki
I finally found a simple solution to the problem

\define text-pattern-backlink()
\u005B\u005B$(currentTiddler)$\u005D\u005D
\end

filter
="[all[current]backlinks[]] [regexp:text<text-pattern-backlink>] -[is[current]] -[tag[hide]] -[is[system]]"

This filter can find backlinks that the default backlink filter can't find (for example inside a macrocall)

Thank you everyone for your help!

TW Tones

unread,
Aug 18, 2020, 10:53:56 PM8/18/20
to TiddlyWiki
Kebi et all

Posting a clarification for future visitor to this thread.

Backlinks has both a plain language meaning and a specific one in Tiddlywiki (The result of the backlinks operator)

Just keep in mind "[regexp:text<text-pattern-backlink>]" is not finding backlinks, you are finding tiddlers named in Square brackets, 
  • although often they are backlinks, and in your example you use "[all[current]backlinks[]]" to get the current tiddlers backlinks.
  • but you will also get missing tiddlers as defined by [[tiddler name]] (Which are really backlinks only if the tiddlername exists)
  • you will not retrieve TiddlerName which becomes a link, and a backlink due to being camelCase (unless its in the currentTiddler)
Also I expect Eric's solution does almost the same as your final answer.


Regards
Tony
Reply all
Reply to author
Forward
0 new messages