building a table with a macro

148 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Oct 9, 2020, 10:48:28 AM10/9/20
to TiddlyWiki
Hi! In the pursuit of my goal, I am not wanting to build a table. I've been able to get the raw wiki code I would have written, but I can't have it correctly interpreted, despite my using the wikify widget with html output. I'm inclined to thin that this is something to do with line breaks within a variable. But let's see the code fiest!

\define compter(tagg) <$count filter="[tag[critère $tagg$]butlast[]]"/> tagués
\define listCriterions()
\whitespace trim

|les <$count filter="[all[current]tagging[]butlast[]]"/>&nbsp;critères liés aux {{!!title}}|c
| Code | Tests  |Libellé|h
<$list filter="[all[current]tagging[]butlast[]]" variable="crit">
|<$link to=<<crit>>><$transclude tiddler=<<crit>> field="code"/></$link>|<$count filter="[tag<crit>]butfirst[]" />|<$transclude tiddler=<<crit>> field="criterion"/>|
</$list>
\end

\define theme()
<$wikify name="line" text="""<<listCriterions>>""" output="html"><<line>></$wikify>

!!! Note
{{ETSI EN 301 549}}
\end

----
!! listCriterions

<<listCriterions>>

----
!! theme

<<theme>>

And here is screen capture:

bug-table-build.png
We get the same resut with or without wikify. We have links when they are written in a tw syntax, sot I think those two clues really show that the recurse to wikify may not be useful. I tried the same thing with a blank line before closing the $list widget, but this changed nothing.

I also notice that there is no space arount the numbers transcluded in the legend of the table (except after the first number, where I set an unbreakable space entity. This does not seem the usual comportment for me, and that may be a clue as to what is wrong. But I habe no idea.

two side notes:
1) there is no example in the wikify widget documentation, to show what effect it really has.
2) it would be nice to be able to see the raw output of my macro, but I'm not sure how to do this. javascript may help, especially via the javascript console. What are you doing for this, folks?

Regards and thaks in advance!

Jean-Pierre Rivière

unread,
Oct 9, 2020, 10:57:15 AM10/9/20
to TiddlyWiki
I'm wondering if the key of my problem is not this sentence at the end of the "Transclusion and Substitution" documentation:

"Transclusions are processed independently, and cannot be combined with adjacent text to define WikiText constructions."

Because I am laying out the title and headers ogf my table first, then I'm doing the list widget to repeat a mechanism of transclusion for each row.

If this is the case, I suspect that I would need to write a javascript macro that would output the whole table in one row. An other possibility would be that my current macros output html, but I'm not keen on that idea within a wiki.

TW Tones

unread,
Oct 9, 2020, 6:14:47 PM10/9/20
to TiddlyWiki
Jean-Pierre,

The first line of the table does not match what follows.

|les <$count filter="[all[current]tagging[]butlast[]]"/>&nbsp;critères liés aux {{!!title}}|c
| Code | Tests  |Libellé|h

ie
| |c
| Code | Tests  |Libellé|h

Unless you use > etc.. to define it correctly the table will not render correctly.

Otherwise I expect it would work (I have not looked at the other details.

Personally I use HTML for complex tables the tr th td tags especially containing lists as there are easier to debug.  I no longer use the sort table definition method 

Regards
Tony

TW Tones

unread,
Oct 9, 2020, 6:15:39 PM10/9/20
to TiddlyWiki
Yes, I see my mistake, it the caption. sorry.

Jean-Pierre Rivière

unread,
Oct 9, 2020, 6:51:35 PM10/9/20
to TiddlyWiki
I have confirmation of a problem with end of line with macro rendering text, not with wiki parsing after the macro has done its job.

simply surrond the macro call by pre and /pre tags. And behold below!

bug-no-lines.png
There is clearly a bug or a missunderstanding from my part. If I put a blank line after the header line and each line in the loop, within the macro definition, this does not change anything.

Eric Shulman

unread,
Oct 9, 2020, 9:43:46 PM10/9/20
to TiddlyWiki
On Friday, October 9, 2020 at 3:51:35 PM UTC-7, Jean-Pierre Rivière wrote:
I have confirmation of a problem with end of line with macro rendering text, not with wiki parsing after the macro has done its job.
simply surrond the macro call by pre and /pre tags. And behold below!

Table syntax requires newlines to terminate each row.  However, your macro specifies "\whitespace trim",
which eliminates the newlines.   Thus, your generated table output becomes one long run-on line of text
and the "|" dividers are treated as literals.

Wikitext table syntax can be very sensitive to subtle issues with whitespace (e.g., a single
space character following the last "|" on a row will break the table output.  Also, as you've discovered,
you can't use <$list>...</$list> to generate rows with wikitext table syntax, since the presence of the
widgets also breaks the table output.

In general, when programmatically constructing complex table output, I suggest using HTML table
syntax (i.e., table, caption, th, tr, td) instead of wikitext table syntax, as it will permit much greater
flexibility and produce more controllable results.

-e


Jean-Pierre Rivière

unread,
Oct 10, 2020, 2:37:14 AM10/10/20
to TiddlyWiki
Thank you Eric. When I got up one hour ago, I got myself the revelations that I had done the error of using the \whitespace trim pragma error! So I immediatly corrected my macro, before anything else (including going here to check any answer).

I got a way to produce the raw ouput I wanted. But it is not correctly rendered, even though by copying the output between pre and /pre I have the table output I want (that's shown at the bottom of the picture). Yes, I had to make some clever but ugly layout of the markup to achieve that goal of getting the raw text I needed.

But the table was still not well rendered. Yet, as I copied the output within "pre" and "/pre" tags I used to check my code, I got my table right!

And then I got the illumination :o)

In my copied-text table, I had no links! Whereas I got them between the "pre" and "/pre" tags! That was just because, in fact, I was not looking at the wikintext code I would have coded manually. Which means that I would need to reproduce that code as a result of my macro. Which would clutter the macro code. Way worse than using html for table as I've been told twice!

SO I will obey your wise counsel and go for direct html table coding.

However, here is the example code for getting a wiki text of a table (a simple wiki text with no links or other fancy stuff, including in what tou transclude (which was not hte case for the "criterion" filed in my case).

\define listCriterions()
|les <$count filter="[all[current]tagging[]butfirst[]]"/> critères liés aux {{!!title}}|c
| Code | Tests|Énoncé|h
<$list filter="[all[current]tagging[]butfirst[]]" variable="crit">|<$transclude
tiddler=<<crit>> field="code"/>|<$count
filter="[tag<crit>]butfirst[]" />|<$transclude
tiddler=<<crit>> field="criterion"/>|
</$list>
\end

The trick is to open the next widget after a pipe "|" at the end of a line, but to terminate that widget on the new line to avoid getting one very long line!

Thank you all for your help! I've learnt a lot once again.

Jean-Pierre Rivière

unread,
Oct 10, 2020, 12:02:52 PM10/10/20
to TiddlyWiki
I thought I had not tested my code, which is not the way to behave in this forum. So I got to test it. And...

I was still WRONG !

I mean, I've come up with code that can output a wikitext fit for coding a simple table. But no way to get the table rows... Even if my code is not within a macro, the result is the same. What's wrong there?

The code (not in a macro):

|les <$count filter="[all[current]tagging[]butfirst[]]"/> critères liés aux {{!!title}}|c
| Code | Tests|Énoncé|h
<$list filter="[all[current]tagging[]butfirst[]]" variable="crit">|[[{{<$transclude tiddler=<<crit>> field="code"/>!!code}}|<<crit>>>]]|<$countfilter="[tag<crit>]butfirst[]" />|<$transclude
tiddler=<<crit>> field="criterion"/>|
</$list>

The output (captured beween "pre" and "/pre"):

|les 2 critères liés aux cadres|c
| Code | Tests|Énoncé|h
|2.1|1|Chaque cadre a-t-il un titre de cadre ?|
|2.2|1|Pour chaque cadre ayant un titre de cadre, ce titre de cadre est-il pertinent ?|

If I copy paste this out put, yes I have my table OK. But if I see the output of my code within the tiddler it is written, I get the table headers and title, and then the rows as raw text condensed within one line. Must be a magic somewhere beyond my knowledge...

bug-with-simple-table.png
Reply all
Reply to author
Forward
0 new messages