Hello!

There's a feature I've wanted to see in TiddlyWiki for a while:  The 
ability, when using the $list widget, to create a variable corresponding to 
the position of the current item in the list.  My interest in this feature 
is to use it for coordinates when generating SVGs.  I took the initiative 
of making a crude working implementation.  Modifying the list widget proved 
a bit intimidating, so I implemented a filter operator instead.

The new operator is attached and can be imported to a wiki.  It is called 
*addposition*, and formats each title in the input list into some 
combination of title, list position, list size and customizable delimiters. 
 The intended use is to glue positions onto each list item and un-glue them 
later with string operations.

The filter operand is a format string, where T is replaced by the input 
title, P by the position and N by the size of the list.  The default format 
(when calling addposition[], no operand) is "P:T".  Prefix notation makes 
it easy to use the splitbefore operator.

Example code:

<table>
<tr><th>index</th><th>tiddler</th></tr>
<$list variable="item" filter="[all[shadows]regexp[list]sort[title]
*addposition[P/N:T]*]">
<$set name=pos filter="[*<item>splitbefore[:]removesuffix[:]*]">
<$set name=tiddler filter="[*<item>removeprefix<pos>removeprefix[:]*]">
<tr>
  <td>^^#^^<<pos>></td>
  <td><<tiddler>></td>
</tr>
</$set>
</$set>
</$list>
</table>

If this function proves useful to others, it might be worth investigating 
position and/or size variable options in the $list widget itself, which 
would be somewhat more convenient to use.

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/137f215e-ffaa-4ccc-bf76-17871a360b45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: $__ebalster_modules_filters_addposition.json
Description: application/json

Reply via email to