building a list of external links from a tiddler field

170 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Oct 1, 2020, 11:39:59 AM10/1/20
to TiddlyWiki
My aim is to build al ist of external links from the value stored within a field of the current tiddler. This value is something like "C14 H1665 SM1113".

Thanks to a lot of help from this forum, I have been avle to build a macro which translate each of those word into an external link.

But I am unable to go any further.

The macros and filters of tiddlywiki are provided to cater for tiddler titles, like the list-links widget. I can produce the complete html that would achieve my goal with filters thanks to subfilter. But I have discovered I cannot display that html. Some mocked attemps are below:

!!! text
<$text text="""<ul><li>un</li><li><a href="#147">deux</a></li></ul>"""/>

!!! wikify sur html
<$wikify name="toto" text="""<ul><li>un</li><li><a href="#147">deux</a></li></ul>""">
<<toto>>
</$wikify>

!!! wikify sur html + wiki
<$wikify name="toto" text="""\n\n* un\n* <a href="#147">deux</a>""">
<<toto>>
</$wikify>

As you can see, even wikify seems unable to make a list.

What is the way of displaying puere html or a mix of tw5 + html?

There is a possibility with inclusion of a field. But my field cannot be included as raw. So I could process it and create an other field with the terget html. But how can I create this filed automatically? I have seen the action-setfiled widget, but I've been unable to trigger it when not associated with a button (and there is no button). My code for this attempt:

<$action-setfield field="jack" value="""<h2>html</h2> <ul> <li>un</li> <li><a href="https://meddurenos.free.fr">deux</a></li> <li>trois</li> </ul>"""/>
<$transclude field="jack" mode="inline"/>

Could I use some clever javascript to trigger the action-setfield gagdet, with eventually an hidden button if need be?

Abandoning that track, should I go for a macro instead? Should/could it be a macro that would take as input a listed filter (use of the filter operator within a filter) -- which I don't know how to do yet? Should I write a javascript macro or filter to help me?

TW Tones

unread,
Oct 1, 2020, 7:41:54 PM10/1/20
to TiddlyWiki
Jean-Pierre Rivière

I am not sure what you are trying to achieve in the end. 
  • Is this to be in the aforementioned static tiddler template?
  • Are you trying to generate HTML? (I have some great tips if you are)

Most of Html works in its own right in tiddlers, so if you use the wikitext to create a link https://tiddlywiki.com/#Linking%20in%20WikiText
 it is rendered to html on your screen.

It seems to me your attempt at storing html in fields is unnecessary, I cant imagine a case where this is necessary.

Regards
Tones

Jean-Pierre Rivière

unread,
Oct 2, 2020, 6:04:43 AM10/2/20
to TiddlyWiki
Here is a sample of what I had written by hand:



With my wcag macro, I can now write something like

* <<wcag G10>>,
* <<wcag G135>>,
etc...

What I want to achieve;
- I have a field called "wcag21tech" which would hold something like "G10 G135 G136 F15 .... ARIA19 SCR21]]
- I want to be able to either write the code with macro I currently have and have it interpreted as wiki text or if that would be impossible, directly write final html and display it.

I have found I can render html easily via transclusion from a field. I'd be keen to know what you know, because sooner or later it might save my day.

At first, I thought I could do something a bit like

<<list-links filter:"[subfilter{!!wcag21tech}addsuffix[?]]">>

but it does not do what I want because list-links is only intended for internal links and it would try to internalize my external links.

Regards,

TW Tones

unread,
Oct 2, 2020, 9:23:04 AM10/2/20
to TiddlyWiki
Jean-Pierre,

Paste this into a tiddler and review how it works.

\define link-prefix() https://www.w3.org/WAI/WCAG21/Techniques/
\define link-codes-macro() general/G10 general/G135 general/G136 failures/F15
\define links() [[$(link-code)$|$(link-prefix)$/$(link-code)$]]
\define hyper-links() <a href="$(link-prefix)$$(link-code)$" target=W3.org><$text text={{{ [[$(link-code)$]split[/]last[]] }}}/></a>

;List from macro
<$list filter="[enlist<link-codes-macro>]" variable=link-code>
 
<<links>>
</$list>

;List from field
<$list filter="[enlist{!!links-field}]" variable=link-code>
  <<links>>
</
$list>

;List from [[tiddler|links-tiddler]]
<$list filter="[enlist{links-tiddler}]" variable=link-code>
 
<<hyper-links>><br>
</$list>

links-field contains
failures/F15 failures/F19 failures/F20

links-tiddler contains
aria/ARIA4 aria/ARIA5 aria/ARIA18

Notes;
  • The three list demonstrate different methods
  • All make use of $(varname)$ substitutions to assemble/concatenate the links 
  • I recommend the last that uses the href because it sets a single target name and all links open and replace the last one in the widow/tab
    • You can always use crtl-click to open each in an independent tab.
    • This also demonstrates how to build HTML but that is most often unnecessary.
  • You can see it's only in the last list that I discovered the 2nd last part is needed to make the link unique.
    • Only the link-prefix is the same for all links.
  • The macro can be made global too.
Regards
Tones


Jean-Pierre Rivière

unread,
Oct 2, 2020, 6:21:55 PM10/2/20
to TiddlyWiki
Thank you Tones. I need to adapt it to my very need, but something I have not been able to do quickly tonight is to get a list (the ul/li or ol/li kind of list) with that. for instance, in list from field, having "* <<links>>" instead of "<<links>>" doesn't do the tricks. I confess I don't understand why.

Note that I can get my list if I add the html tags correctly:

;List from field
<ul>
<$list filter="[enlist{!!links-field}]" variable=link-code>
  <li><<links>></li>
</$list>
</ul>

But I would prefer using a wiki syntax. A use case for wikify widget maybe, I haven't tested it yet.

Regards, 

(BTW how do you insert specific portion of code in your post? I'm unable to do this.)

TW Tones

unread,
Oct 2, 2020, 8:07:03 PM10/2/20
to TiddlyWiki
Jean-Pierre,

When we use the content of the list widget as the template to display each item, there is a different behaviour if the first line is blank or not. No line makes it inline, one blank line makes it a block, so line based wiki text is processed.

;List from [[tiddler|links-tiddler]]
<$list filter="[enlist{links-tiddler}]" variable=link-code>

* <<hyper-links>>
</$list>

However if you look at the html output the
<ul>
is started again for every item, so there is a larger gap between items.

Keep in mind to a great extent wikitext mark-up is about shorthand, when using widgets such as the list widget it not so critical to use only mark-up, so your html solution is fine.

Tones

Jean-Pierre Rivière

unread,
Oct 6, 2020, 10:27:50 AM10/6/20
to TiddlyWiki
OK. Thanks to you, I got these macros to get my job done. Note the padding on the ul tag to get an alignment not excessively deported to the right. 

\define wcag(ref)
\whitespace trim
<$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[/]] }}} >
<a href=<<url>> target="w3.org/WAI/">$ref$</a>
</$vars>
</$wikify>
</$set>
</$set>
\end

\define wcagList()
<ul style="padding-left: 0;">
<$list filter="[enlist{!!wcag21tech}]" variable=link-code>
  <li><$macrocall $name="wcag" ref=<<link-code>> /></li>
</$list>
</ul>
\end

Note also the call to the wcag macro using the macrocall widget. I would have tought that I could have instead written this:

<li><<wcag $(link-code)$>></li>

Eric Shulman

unread,
Oct 6, 2020, 11:01:11 AM10/6/20
to TiddlyWiki
On Tuesday, October 6, 2020 at 7:27:50 AM UTC-7, Jean-Pierre Rivière wrote:
\define wcagList()
<ul style="padding-left: 0;">
<$list filter="[enlist{!!wcag21tech}]" variable=link-code>
  <li><$macrocall $name="wcag" ref=<<link-code>> /></li>
</$list>
</ul>
\end

Note also the call to the wcag macro using the macrocall widget. I would have tought that I could have instead written this:
<li><<wcag $(link-code)$>></li>

You can only use the $(...)$ syntax to substitute values from variables that are defined *outside* of the macro.
However, "link-code" is defined *inside* the macro, so you can only use the <<link-code>> variable reference
which is why you also needed the $macrocall syntax.

-e
Reply all
Reply to author
Forward
0 new messages