Comma-separated lists in TW5

332 views
Skip to first unread message

Rob Hoelz

unread,
Nov 28, 2017, 1:26:08 PM11/28/17
to TiddlyWiki
Hi TiddlyWiki users and devs!

I'm working on a piece of UI for a plugin I wrote, and I would like to render a list of items as a comma-separated list.  Unfortunately, I can't seem to wrap my head around how to do this - at first I thought to use $reveal, but that depends on state in a tiddler field, and then I tried $set with a filter to match the first item in the list, but that didn't seem to work either.  Does anyone have any experience with this who could shed some light on the matter?

Thanks,
Rob

Jed Carty

unread,
Nov 28, 2017, 1:41:51 PM11/28/17
to TiddlyWiki
If you are using a list widget than you just go like this:

<$list filter=<<YourFilter>>>
<
<currentTiddler>>,
</$list>

to prevent a trailing comma on the last item you can do this:

<$list filter='[tag[HelloThere]]+[butlast[]]'>
<<currentTiddler>>,
</$list>
<$list filter='[tag[HelloThere]]+[last[]]'>
<<currentTiddler>>
</$list>

Rob Hoelz

unread,
Nov 28, 2017, 2:54:10 PM11/28/17
to TiddlyWiki
Ah, good trick - thanks!

Alex Hough

unread,
Nov 29, 2017, 7:13:16 AM11/29/17
to TiddlyWiki
a related question...

I have a comma separated list, how could I make the phrases be converted to wikilinks?

I was thinking of a macro which would take the list and output the links



Alex

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d9c68edf-14ff-48e9-a649-9cd43f294810%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jed Carty

unread,
Nov 29, 2017, 7:45:00 AM11/29/17
to TiddlyWiki
The first response is: Do you have to use comma separated lists for the input instead of using the native tiddlywiki list format? Because if you use the native format than you can just use normal filter operators.

The actual answer to your question is to put this in a tiddler with the tag $:/tags/Macro then you can use the macro SplitCommaList:

\define InnerSplitCommaList()
<$list filter="""[<CurrentList>splitbefore[,]removesuffix[,]]""" variable=CurrentItem emptyMessage="""<$link to=<<CurrentList>>><<currentList>></$link>""">
<$link to=<<CurrentItem>>><<CurrentItem>></$link>
<$set name=CurrentList filter='[<CurrentList>removeprefix<CurrentItem>removeprefix[,]]' emptyValue=<<CurrentList>>>
<<InnerSplitCommaList>>
</$set>
</$list>
\end

\define SplitCommaList(list)
<$set name=CurrentList value="""$list$""">
<$set name=CurrentList filter='[<CurrentList>addsuffix[,]]'>
<<InnerSplitCommaList>>
</$set>
</$set>
\end

Usage:

Directly give the list:

`<<SplitCommaList """a,b,c""">>`

<<SplitCommaList """a,b,c""">>

Using a text reference:

`<<SplitCommaList {{!!field_with_comma_list}}>>`

<<SplitCommaList {{!!field_with_comma_list}}>>

the second set widget adds a comma to the end of the list because checking to see if you are on the last item and there is no trailing comma is a pain otherwise. This works with lists with and without trailing commas.

Alex Hough

unread,
Nov 29, 2017, 9:29:38 AM11/29/17
to TiddlyWiki
Hi Jed,

the use case from which this emerged was cut and pasting a comma separated list from a PDF then wanting to create tiddlers for each in the list. Part of a process of convering a PDF into an extensible document and orgnaisational model.

I cut and paste the text into one side of the edit template, then use the right hand side to crreate tiddlers.

I thought of an input resempling something like this

<<.macroName "music, food, art, gardening, performance" >>

It could be used to turn a sentence from a static text into an interface for creating a model.

The marco could create tag pills, there could be a new here button at the top. 

The process would be taking annotation of a text one step further: the annotation adds the capacity to build on lists within the existing text.

Alex

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Jed Carty

unread,
Nov 29, 2017, 11:49:08 AM11/29/17
to TiddlyWiki
The macro I made should be able to be modified. Just change the line <$link to=<<CurrentItem>>><<CurrentItem>></$link> to whatever you want displayed for each item in the list.

Ste Wilson

unread,
Nov 29, 2017, 1:16:51 PM11/29/17
to TiddlyWiki
If you tidy it up and save as a csv (text editor or excell) file you might find www.tablesgenerator.com/html_tables use full.

Mat

unread,
Dec 1, 2017, 10:30:16 AM12/1/17
to TiddlyWiki
Rob Hoelz wrote:
[...] render a list of items as a comma-separated list.


I had the same problem just some weeks ago. Solved it with CSS like so:

<div class="commas"><$list filter="..."/></div>

<style>
.commas span:not(:last-child):after {content:", ";}
</style>


<:-)
Reply all
Reply to author
Forward
0 new messages