currentTiddler in function - Is this odd or am I missing something?

Folks,

to solve this issue;

I wrote a function as follows;

\function pretty.permalink() [<open-sq>] [<currentTiddler>] [<close-sq>] [[(]] [{$:/info/url/full}] [[#]] [<currentTiddler>] [[)]]  +[join[]]
\define open-sq() [
\define close-sq() ]

<<pretty.permalink>>

I dont understand the result;

[](file:///I:////!Master/KeyWikis/BlogToSelf.html#New Blog Tiddler 13)

Why does the [] not contain the current tiddler?

Even this simple form

\function pretty.permalink() [<currentTiddler>] [[something]] [<currentTiddler>] +[join[]]

<<pretty.permalink>>

Fails with the first use of [<currentTiddler>] not being returned.

Tested in TW 5.3.7, 5.3.8 and 5.4.0-prerelease now

You need to add the =/:all filter run prefix before [<currentTiddler>] (and any other repeated strings) to prevent deduplication. Otherwise, only the last instance of a given string will be preserved in the results.

Incidentally, for functions that use “problematic” characters like square brackets, I often like to define the special characters as parameters of the function (following any parameters that might be set dynamically). So I might rewrite your function like this:

\function pretty.permalink(open-sq:"[", close-sq:"]") [<open-sq>] =[<currentTiddler>] [<close-sq>] [[(]] [{$:/info/url/full}] [[#]] =[<currentTiddler>] [[)]] +[join[]]

<<pretty.permalink>>

Of course, if you use <<open-sq>> and <<close-sq>> frequently, it makes more sense to make them global variables (which you may already have done!) But for more ad hoc situations, like regex, I find it very convenient to keep all my static variables in the same function.

2 Likes

haha thanks,

It was staring me in the face but I could not see it. to me they were not unique as they were to be wrapped up differently, but that will be after deduplication :man_facepalming:

nice approach using parameters, keeping simple strings local, using them as local variables only, now procedures/functions make parameters into variables.

:pray:

1 Like

I have correct this and its working for both tiddlywiki pretty links and markdown.

Some observations;

  • The tiddler title part of the URL needs encodeuri so it is not longer a duplicate of [<currentTiddler>]
  • Doing the same for file:///D:/pathandfile however does not seem to work. This is for a link to an external wiki, for same wiki we may as well use the built in ctrl-L etc…

Does this mean there is a bug or gap in the Markdown links to file addresses?

For the record is someone wants to know

For markdown Pretty permalinks

\function pretty.permalink(open:"[",close:"]") [<open>] =[<currentTiddler>] [<close>] [[(]] [{$:/info/url/full}] [[#]] =[<currentTiddler>encodeuri[]] [[)]]  +[join[]]

For tiddlywiki Pretty permalinks

\function pretty.permalink(open:"[[",close:"]]") [<currentTiddler>addprefix<open>] [[|]] [{$:/info/url/full}] [[#]] [<currentTiddler>addsuffix<close>] +[join[]]

Working buttons attached;
pretty-permalinks.json (4.0 KB)
updated with green and red buttons

I’m not quite clear about the context. But if you’re trying to link from a wiki served over http(s)://... to one served as file:///..., then browsers are not going to allow that, for some important security reasons.

8 posts were split to a new topic: About Browser Security Policies

Thanks for posting this, @etardiff — I realize that even when I do have a global variable defined, any functions that I want to be portable really should do as you model here, so that I’m not at risk of dragging a function to a new wiki without bringing along the global variables.

Furthermore, in theory it could happen that someone drags my solution into another wiki that relies on a conflicting definition of that global variable! But if it’s being locally specified right in the function, then there’s even less risk that importing my global variable (bundling it somehow with the function) would mess up something else.

1 Like