confused by URL generation

97 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Sep 20, 2020, 6:30:48 PM9/20/20
to TiddlyWiki
I want to generate URL. The aim would be to generate something like that:

with G8 or H96 a input.

At first, I tried 

\define wcagTechUrl(ref)
<$set name="place01" filter="[[$ref$]prefix[G]then[general]]">
<$set name="place02" filter="[[$ref$]prefix[H]then[html]]">
<$set name="url" filter="https://www.w3.org/WAI/WCAG21/Techniques/ <<place01>> <<place02>> / $ref$ +[join[]]">
[[$ref$|<<url>>]] link to <<url>>
</$set></$set></$set>
\end

and this gives me that kind of things : bug-01.jpeg
* there is a G8 link but it links to #<<url>>
* the link outside of the "a" tag is treated as a link but only until "Techniques/" corresponding to the URL I added during the join operation.

I trie the following new code:

\define wcagTechUrl(ref)
<$set name="place01" filter="[[$ref$]prefix[G]then[general]]">
<$set name="place02" filter="[[$ref$]prefix[H]then[html]]">
<$set name="url" filter="https://www.w3.org/WAI/WCAG21/Techniques/ <<place01>> <<place02>> / $ref$ +[join[]]">
<$wikify name="urlw" type="text" text=<<url>> >
<<urlw>>
</$wikify>
</$set></$set></$set>
\end
\define wcagTech(ref) [[$ref$|<<wcagTechUrl $ref$>>]] vers <<wcagTechUrl $ref$>>

which I use thus: <<wcagTech G8>> and I get bug-02.jpeg
* the macrocall widget is no better that the simple macro calling, same result
* but the printed url is shown as a complete URL, that which I want, and redirect to that URL.

So, I'm really confused. the URL in the [[ | ]] link syntax is always raw, I can't use a macro or a variable to speicy it, which ruins my second attempts and similar tries. And my first try was also very strange.

Could a guru explain me waht's going on or how to do it properly please? Many thanks in advance!!!



but the result is that one

Joshua Fontany

unread,
Sep 20, 2020, 7:52:12 PM9/20/20
to TiddlyWiki
Hi,

I know that TW syntax can be overwhelming. Let's cut this back to its simplest form.

Macros are used primarily for Text Replacement. That is, then the macro is "called" the wiki-text parser tries to complete all text replacement in the macro-body using the inputs, and _then_ it parses the resulting text AS wikitext as per normal.

So the simplest implementation would be (note the use of the "ext" modifier for the link quick-syntax, this forces an external link):
```
\define wcagTechUrl(ref)
\end

<<wcagTechUrl H96>>
```

While it is now easy to write these macro-links via plaintext, you would not want to use this form inside a $list or other widget construction. Use the below pattern instead. I have "unpacked" the macro-call quick-syntax. This allows us to pass other variables or tranclusions to the input of the macro. In this case the tiddler title of any tiddler tagged "wcagTechUrl" in a $list construction (using the default "currentTiddler" variable by omitting the "variable" parameter of the $list):
```
\define wcagTechUrl(ref)
\end

<$list filter="[tag[wcagTechUrl]]">

<$macrocall $name=wcagTechUrl ref=<<currentTiddler>> />
</$list>
```
Best,
Joshua Fontany

Eric Shulman

unread,
Sep 20, 2020, 7:54:56 PM9/20/20
to TiddlyWiki
On Sunday, September 20, 2020 at 3:30:48 PM UTC-7, Jean-Pierre Rivière wrote:
I want to generate URL. The aim would be to generate something like that:
with G8 or H96 a input.

Here's one way to make your code work:
\define wcagTechUrl(ref)
<$set name="place01" filter="[[$ref$]prefix[G]then[general]]">
<$set name="place02" filter="[[$ref$]prefix[H]then[html]]">
<$set name="url" filter="[[https://www.w3.org/WAI/WCAG21/Techniques/]] [<place01>] [<place02>] [[/$ref$]] +[join[]]">
<<wcagTechUrl_makelink "$ref$">>
</$set></$set></$set>
\end

\define wcagTechUrl_makelink(ref) [[$ref$|$(url)$]]

which can be invoked like this:
<<wcagTechUrl G8>>

Note the brackets used in the filter expressions: [[...]] surrounds literal text, and [<...>] surrounds variables.
Note also the makelink() helper macro to construct the "pretty link" wikitext output.

You could also write the filter using "addsuffix[...]" operators instead of using "join[]", like this:
<$set name="url" filter="[[https://www.w3.org/WAI/WCAG21/Techniques/]addsuffix<place01>addsuffix<place02>addsuffix[/$ref$]]">

Another alternative (and perhaps the simplest) is to skip the filter syntax entirely and use macro substitution handling in the makelink() helper macro to construct the URL and wikitext link syntax in one go, like this:
\define wcagTechUrl(ref)
<$set name="place01" filter="[[$ref$]prefix[G]then[general]]">
<$set name="place02" filter="[[$ref$]prefix[H]then[html]]">
<<wcagTechUrl_makelink "$ref$">>
</$set>
</
$set>
\end
\define wcagTechUrl_makelink(ref) [[$ref$|https://www.w3.org/WAI/WCAG21/Techniques/$(place01)$$(place02)$/$ref$]]

enjoy,
-e

Jean-Pierre Rivière

unread,
Sep 22, 2020, 12:17:02 AM9/22/20
to TiddlyWiki
Thanks Eric. This is what I needed.

Now, I can go further. I have several refrences to WCAG within each tiddler concerned, and I'd like to store them inside a tiddler field named "wcag21tech" and a typical contents would be "G8 G58 G78 G173 H96 SM1 SM2 SM6 SM7". This should be translated as a list of hyperlinks "G8", "G58", etc by the same rules than wcagTechUrl, but wcagTechUrl is a macro and not a list. I have seen that the macro filter "subfilter" can really be a "map" function and I would then need to write a filter in javascript to be able to use subfilter to generate a list of hyperlink from a list of referencess.

I don't know how to cal a macro from each member of the array that would be derived from my wcag21tech. It seems to be totally out of question. So really I need to write that javascript filter. I think this filter should return an array of wikitext and not an iterator function. But this is quite new stuff for me. So I decided to begin small with q very very simple filter that always return an array of a single string which is always "fubar". I read https://tiddlywiki.com/dev/ "Filter Operators" to start this. But from then on, I think I will have to be in the dev list for building filters, won't I?

Jean-Pierre Rivière

unread,
Sep 22, 2020, 12:23:54 AM9/22/20
to TiddlyWiki
@Joshua: Thank you for your answer. I had tries with <$macrocall> but it was not the gotcha. What I had wrong was really, in retrospect, the art of puting [, ( and < right within my filters. I am still dumbfounded by what the way-that-works vs the way-that-I-would-thought-would-work.

I'm now looking at the subfilter filter. It seems to be the map operator I was asking for. But here again, I have two problems: 1) writing my filter and 2) using subfilter!

But those problems do not belong to this thread.

Regards,

TW Tones

unread,
Sep 23, 2020, 1:16:27 AM9/23/20
to TiddlyWiki
Just a general suggestion;

When providing a large number of links to similar resources on the same external website/wiki I personally construct links based on the html a element. The key reason is we have access to the target parameter.

You still use similar techniques to create the links but the result can be something like this;


The key advantage is it keeps opening in the same tab/window rather than opening too many tabs/windows, yes one replaces the other but this can be appropriate.

Regards
Tones

Jean-Pierre Rivière

unread,
Sep 23, 2020, 3:26:59 AM9/23/20
to TiddlyWiki
@Tones: Many thanks for this tip. I was not aware of such a use for the "target" attributes. This is indeed very appropriate to my use case! And to get it on a different tab, I can click with the middle mouse button. That's a winner!

Jean-Pierre Rivière

unread,
Sep 23, 2020, 5:03:08 AM9/23/20
to TiddlyWiki
marked the thread as [solved] (or tried to mark it so! ;-)
Reply all
Reply to author
Forward
0 new messages