unwanted space in, macro result

163 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Sep 24, 2020, 2:14:03 PM9/24/20
to TiddlyWiki
I have spaces surrounding the result of my macro call, even though the result is spaceless. Yet again somethink that I must have overlooked...

Here is the macros code:

\define getWcagDir() <$transclude tiddler="$:/user/dict/wcag/ref/cat" index="$(codeFamily)$"/>
\define wcagTechDict(ref)
<$set name="codeFamily" filter="[[$ref$]splitregexp[\d+]join[]]">
<$macrocall $name="getWcagDir"/>
</$set>
\end
\define wcagUrl(ref)
<<base>><<wcagTechDict "$ref$">>/$ref$ />
</$set>
\end

Here is the dictionnary $:/user/dict/wcag/ref/cat

ARIA:aria
C:css
F:failures
G:general
H:html
SCR:client-side-script
SM:smil
SVR:server-side-script

Here is the user code with call to the wcagUrl macro

SM8 in <<wcagTechDict SM8>> to <<wcagUrl SM8>>

Here is the result:


(with a link only from https: up to Techniques/ which is also a problem).

I tried a trim[] after the join[] in the filter. It was redundant, it had no effect.

I tried an other definition for this macro:

\define wcagUrl(ref)
<$set name="url" filter="[[<base>] [<wcagTechDict "$ref$">] [/$ref$] +[join[]]]">
<<url>>
</$set>
</$set>
\end

but the result is beyond me:

SM8 in smil to <$set name="url" filter="<base>] [<wcagTechDict "SM8">] [/SM8] +[join[]"> </$set>

(with a link from <base> up to +[join[ in the bargain).

Any idea you gurus? (as an ancient Amiga owner, I respect much gurus!)



Hubert

unread,
Sep 24, 2020, 2:59:14 PM9/24/20
to TiddlyWiki
Hi,

I haven't studied your code in its entirety (I'm currently on mobile) but maybe try adding \whitespace trim in the line immediately following your macro definition.

Good luck!
Hubert


Jean-Pierre Rivière

unread,
Sep 24, 2020, 5:07:58 PM9/24/20
to TiddlyWiki
I don't know you \whitespace and can't find any reference to it. And what kind of thing is this ? Anyway, I'm not sure where you mean it to be. My attempts were unsuccessfull.

Eric Shulman

unread,
Sep 24, 2020, 6:44:36 PM9/24/20
to TiddlyWiki
On Thursday, September 24, 2020 at 2:07:58 PM UTC-7, Jean-Pierre Rivière wrote:
I don't know you \whitespace and can't find any reference to it. And what kind of thing is this ? Anyway, I'm not sure where you mean it to be. My attempts were unsuccessfull.

"\whitespace trim" is a special syntax called a Pragma (see https://tiddlywiki.com/#Pragma)
You can put this on a line by itself at the very beginning of a tiddler, or as a line following any \define macro(...)

-e

TW Tones

unread,
Sep 24, 2020, 7:07:24 PM9/24/20
to TiddlyWiki
FYI

In many button tiddlers you will see
\whitespace trim
at the top

\define mymacro()
\whitespace trim
Macros def
\end

Also your filter seems broken
[[<base>] [<wcagTechDict "$ref$">] [/$ref$] +[join[]]]

here is my Guess
[<base>] [<wcagTechDict "$ref$">] [/$ref$] +[join[]]
But what is [/$ref$]

Regards
Tones

Eric Shulman

unread,
Sep 24, 2020, 7:37:21 PM9/24/20
to TiddlyWiki
On Thursday, September 24, 2020 at 4:07:24 PM UTC-7, TW Tones wrote:
Also your filter seems broken
[<base>] [<wcagTechDict "$ref$">] [/$ref$] +[join[]]
But what is [/$ref$]

Note that, while you can use simple <macro> references within filters, they cannot have parameters.  Thus, <wcagTechDict "$ref$"> is not valid within the filter.  Also, [/$ref$] is the last part of the URL that is to be constructed, with a leading literal "/" preceding it.  However, since it is a literal text value expressed as a separate filter run, it needs double brackets, i.e., [[/$ref$]]

-e



Jean-Pierre Rivière

unread,
Sep 28, 2020, 12:48:20 PM9/28/20
to TiddlyWiki
@Eric
I don't understand the [[/$tref$]] construct inside a filter. From the doc, I see that [...] is a filter run. A filter run is made of step and each step is essentially a parameter eventually preceded by ! and/or an operator (with eventual : suffixes). No suare breacket within a step. I heve not read that a run can directly contain a run. So I cannot understand how [[/$ref]] may occur within a filter. I4m also finding strange a step without operator but with an operand (parameter) and the text seems to be ofg the same advice but as far as I read the railroad schema, this may very well happen (no idea of an example for me).

I don't say you're wrong, I'm just saying I don't see how I could have understood that from the official documentation.

Eric Shulman

unread,
Sep 28, 2020, 1:03:22 PM9/28/20
to TiddlyWiki
On Monday, September 28, 2020 at 9:48:20 AM UTC-7, Jean-Pierre Rivière wrote:
@Eric
I don't understand the [[/$tref$]] construct inside a filter. From the doc, I see that [...] is a filter run. A filter run is made of step and each step is essentially a parameter eventually preceded by ! and/or an operator (with eventual : suffixes). No suare breacket within a step. I heve not read that a run can directly contain a run. So I cannot understand how [[/$ref]] may occur within a filter. I4m also finding strange a step without operator but with an operand (parameter) and the text seems to be ofg the same advice but as far as I read the railroad schema, this may very well happen (no idea of an example for me).

I don't say you're wrong, I'm just saying I don't see how I could have understood that from the official documentation.


The step's operator is drawn from a list of predefined keywords, which can be extended by plugins.
Any unrecognised operator is treated as if it was the suffix to the field operator.
If a step's operator is omitted altogether, it defaults to title.

Thus, [[text here]] *is* a filter run containing one filter step that is equivalent to [title[text here]].
Note that you can also specify a filter run that defines literal text values by using quotes,

The lower three options in the diagram match syntax like HelloThere"HelloThere"'HelloThere' and "Filter Operators".

They are short for [title[...]].

The quoted options exist to support titles that contain square brackets, as in "An [[[[Unusual]]]] Tiddler".


-e

Jean-Pierre Rivière

unread,
Sep 29, 2020, 5:07:18 AM9/29/20
to TiddlyWiki
Thank you vet much ineed Eric! I already read that abbreviated form stuff, but it did not got me right on this. Actually, I think the shorter syntax is really difficult into apprehending the filters. For me anyway.

When you read in the schema that a run should obey "one [, then neither [ nor ] then ]" it's a bit difficult to see that a run can be [[helloThere]] because it is the abbreviated form of [title[helloThere]]. I mean, when you'rte out of idea of what was wrong, the documentation is a mixed blessing as it currently is. This form is not bad in itself but it is hard on the newbye. I'd like to have a try at providing further help for the newbye, but I just cannot yet, because I'm just struiggling to get things done.

Abot getting things done, the error message I get most often is "Missing [ in filter expression" which is not very helpful. This is the case, for instance, in the following macro definition:

<$set name="codeFamily" filter="[[title[$ref$]] +join[]]">

There are the same numbers of [ and ] and each [ do precede its corresponfing ]]. Is there an helper tool available to check syntax problems and report them in a more useful way? (and I don't see the syntax problem in my example, although this is just an example, as the code I wanted was filter=[[$refs$]+join[]]" but it is not working as expected either but I'm working on it and it's not my question here).

TW Tones

unread,
Sep 29, 2020, 6:49:08 PM9/29/20
to TiddlyWiki
Jean-Pierre,

We always need to improve info for new users.

You clearly need to learn how to write filters, however within tiddlywiki itself, on tiddlywiki.com, this forum and other community resources there are plenty of examples, after looking at a few you will see how they are constructed.



On Tuesday, 29 September 2020 19:07:18 UTC+10, Jean-Pierre Rivière wrote:
Thank you vet much ineed Eric! I already read that abbreviated form stuff, but it did not got me right on this. Actually, I think the shorter syntax is really difficult into apprehending the filters. For me anyway.

For example [[title[$ref$]] +join[]] has 2 syntax errors "[title[$ref$]join[]]" but [[$ref$]join[]] if it was logical 
But what are you joining? so I don't understand it logically.

Feel free to ask for filter writing support here until you start to understand better. Just give us the information we need so we can give you working answers. 

A good way is to come up with a test case that if it worked we would test it on tiddlywiki.com

Regards
Tones

Jean-Pierre Rivière

unread,
Sep 29, 2020, 7:24:31 PM9/29/20
to TiddlyWiki

I've nearly done the job I wanted.

in my macro tiddler I wrote:

\whitespace trim

\define wcagDir() <$transclude tiddler="$:/user/dict/wcag/ref/cat" index="$(codeFam)$"/>

\define wcag(ref)
<$set name="base" value="https://www.w3.org/WAI/WCAG21/Techniques">
<$set name="codeFam" filter="$ref$ +[splitregexp[\d+]] +[join[]]">
ref: $ref$
base: <<base>>
codeFam: <<codeFam>>
dir: <<wcagDir>>
<$set name="url" filter="[<base>] [<wcagDir>] $ref$ +[join[/]]">
a href=<<url>> target="w3.org/WAI/" LABEL $ref$
</$set>
</$set>
</$set>
\end.png

and in my user tiddler I wrote:

* H18 in wcag: <<wcag H18>>
                                                                        
and thisproduces that:

H18 in wcag: ref: H18 base: https://www.w3.org/WAI/WCAG21/Techniques codeFam: H dir: html a href=https://www.w3.org/WAI/WCAG21/Techniques/<$transclude tiddler="$:/user/dict/wcag/ref/cat" index="H"/>/H18 target="w3.org/WAI/" LABEL H18

 Why the difference for the wcagDir macro calls? I tried playing with the wikify widget but it does not what I wanted (I thought that I need the output of wcagDir be interpreted as wiki text). If I put [{/user/dict/wcag/ref/cat##H}] instead of the transclude widget, it is OK, but I must use a variable and not H, and this I cannot do, and so I thought that the transclude widget would save me.

wcag-macro.png

Eric Shulman

unread,
Sep 29, 2020, 7:27:32 PM9/29/20
to TiddlyWiki
On Tuesday, September 29, 2020 at 3:49:08 PM UTC-7, TW Tones wrote:
For example [[title[$ref$]] +join[]] has 2 syntax errors "[title[$ref$]join[]]" but [[$ref$]join[]] if it was logical 
But what are you joining? so I don't understand it logically.

The syntax in his last post in only part of a larger filter for concatenating multiple parts, like this:
\define makeURL(ref)
<$vars base="https://www.w3.org/WAI/WCAG21/Techniques/">
<$set name="url" filter="[<base>] [<macro1>] [[/]] [<macro2>] [[/$ref$]] +[join[]]">
<<url>>
</$set>
</
$vars>
\end
<$wikify name="url" text=<<makeURL>>
...
</$wikify>

Note that this could also be written without the makeURL macro or $wikify like this:
<$vars base="https://www.w3.org/WAI/WCAG21/Techniques/">
<$vars url={{{ [
<base>] [<macro1>] [[/]] [<macro2>] [[/something]] +[join[]] }}}
...
</$vars>
</$vars>

-e


Jean-Pierre Rivière

unread,
Sep 29, 2020, 7:31:21 PM9/29/20
to TiddlyWiki
what my code want to achieve is:
1) starting from a reference like H18
2) deducing the core of the reference (H for H18)
3) deducing the directory corresponding to that code (html for H) in a dictionnary
4) build an URL from a base url, that directory and that reference: base/directory/reference
5) build a a html tag with that URL and the reference (I have it not as a html tag in my source given here for being easy while writing the code)

Jean-Pierre Rivière

unread,
Sep 29, 2020, 7:54:06 PM9/29/20
to TiddlyWiki
Following your post, I tried wikify and terxt widget. I can't get a simple URL: see the picture. the url stop at the base although the text would be good (otherwise). There is something I have not done here, but what?

the macros code:

\whitespace trim

\define wcagDir() <$transclude tiddler="$:/user/dict/wcag/ref/cat" index="$(codeFam)$"/>

\define wcag(ref)
<$set name="base" value="https://www.w3.org/WAI/WCAG21/Techniques">
<$set name="codeFam" filter="$ref$ +[splitregexp[\d+]] +[join[]]">
ref: $ref$
base: <<base>>
codeFam: <<codeFam>>
dir: <<wcagDir>>
<$set name="url" filter="[<base>] [<wcagDir>] $ref$ +[join[/]]">
<$wikify name="target" text=<<url>> >

* wikify only: a href=<<target>> target="w3.org/WAI/" LABEL $ref$
* wikify then text: a href=<$text text=<<target>>/> target="w3.org/WAI/" LABEL $ref$

</$wikify>
</$set>
</$set>
</$set>
\end



Jean-Pierre Rivière

unread,
Sep 30, 2020, 2:09:51 AM9/30/20
to TiddlyWiki
At last, I've been able to find a solution! Here is the code, featuring a wikify widget to get the text of the transclusion available for buildig the url string.

\whitespace trim

\define wcag(ref)
<$set name="base" value="https://www.w3.org/WAI/WCAG21/Techniques">
<$set name="codeFam" filter="$ref$ +[splitregexp[\d+]] +[join[]]">
<$wikify name="wcagDir"
text="""<$transclude tiddler="$:/user/dict/wcag/ref/cat" index=<<codeFam>> />""" >
<$vars url={{{ [<base>] [<wcagDir>] $ref$ +[join[/]] }}} >

* ref: $ref$ codeFam: <<codeFam>>
* dir: <<wcagDir>>
* prot: <<prot>> base: <<base>>
* url: <<url>>
* link <a href=<<url>> target="w3.org/WAI/">$ref$</a>

</$vars>
</$wikify>
</$set>
</$set>
\end

wcag-macro.png

As you can see in the picture, the link is perfectly OK.

Thank you so much to you all for your patience with me! This has not be in vain.

Eric Shulman

unread,
Sep 30, 2020, 9:02:04 AM9/30/20
to TiddlyWiki
On Tuesday, September 29, 2020 at 11:09:51 PM UTC-7, Jean-Pierre Rivière wrote:
At last, I've been able to find a solution! Here is the code, featuring a wikify widget to get the text of the transclusion available for buildig the url string.
<$wikify name="wcagDir" text="""<$transclude tiddler="$:/user/dict/wcag/ref/cat" index=<<codeFam>> />""" >

I think you could do this without the $wikify, by using an inline filter:
<$vars wcagDir={{{ [[$:/user/dict/wcag/ref/cat]getindex<codeFam>] }}}>

-e

Reply all
Reply to author
Forward
0 new messages