Can Split Up a Dictionary Line of Text Into Separate Items

I once created a todo list type of tiddler, with a new tiddler for each todo item, and I used fields and tags to give each item a context (to show when or where the item should be done) and other properties, like priority.

But it was too cumbersome to add new todo items and manipulate them. To edit an item, for instance, I’d have to open the item’s tiddler and then save my change, then close that individual tiddler, and then find my way back in the scroll to the main list.

I ended up creating a text-based dictionary list and using that, because editing that one file was quick and easy, in terms of adding new items, modifying, or deleting them. I made it super easy, because on the main display tiddler, I added a conditional reveal that showed a text edit control to let me edit the data tiddler directly.

Of course, marking them as “done” was accomplished via the checkbox which pointed to the 0 or 1 value of that dictionary item.

It wasn’t too long before I realized that I liked the dictionary list way much better.

I further enhanced the Dict Todo by giving a numeric prefix to the lines, which acted as a priority. I could change the list filter to just get the priority 2 items, for instance. and of course, I would sort the list, which would show the tiddlers in priority order.

I then added a way to have a context/location associated with the item by putting in @Walmart, for instance, somewhere in the line. I modified the list filter with a regex option to be able to retrieve each specific context.

Here is the data tiddler, with a few items in it to play with …

[{"created":"20220610162910147","text":"1. TAXES: 0\n2. @DollarTree ... Claw-clipping Scissors: 0\n2. @Amazon ....... new Laser printer cartridge: 0\n3. @Amazon ....... Order Faucet gaskets: 0\n4. @Walmart ........ Mason Jars, Smaller ones, Kerr: 0\n4. @Walmart ........ Mason Jars, Large ones: 0\n3. Shelf liners: 0\n3. Ziplocs: 0\n4. Hobby Lobby - Rocket engines: 0","title":"ToDo Item Data","modified":"20220610171110020","type":"application/x-tiddler-dictionary","tags":""}]

And here is a part of the tiddler that groups the items into contexts and then a list of all the items (to get any items that have no context…

[{"created":"20220610163724164","text":"<$tiddler tiddler=\"ToDo Item Data\">\n\n!! Items with a Context/Location\n\n<$list filter=\"[all[current]indexes[]regexp[@\\w\\w+]prefix[2. ]sort[]]\" variable=item>\n    <$checkbox index=<<item>> checked=\"1\" unchecked=\"0\"/> ''<<item>>''<br/>\n</$list>\n<$list filter=\"[all[current]indexes[]regexp[@\\w\\w+]prefix[3. ]sort[]]\" variable=item>\n    <$checkbox index=<<item>> checked=\"1\" unchecked=\"0\"/> <span class=\"pri3\"><<item>></span><br/>\n</$list>\n<$list filter=\"[all[current]indexes[]regexp[@\\w\\w+]prefix[4. ]sort[]]\" variable=item>\n    <$checkbox index=<<item>> checked=\"1\" unchecked=\"0\"/> <span class=\"pri3\"><<item>></span><br/>\n</$list>\n\n---\n\n!! All Items\n\n<$list filter=\"[all[current]indexes[]sort[]]\" variable=item>\n    <$checkbox index=<<item>> checked=\"1\" unchecked=\"0\"/> <<item>><br/>\n</$list>\n\n\n</$tiddler>\n","tags":"","title":"ToDo Items","modified":"20220610171509182"}]

But the list with the contexts was a little hard to read. This is supposed to be a quick-reference list while I’m out doing errands or such. As you can see in the example code, I used dots to align the Most relevant text of the todo (the part after the @context) a little better.

If this can’t be improved upon, then I’m fine, and I’ll stick with this.

But I thought I’d ask, because TW may have a feature that can help me improve this. What about…

String Split (into an array type thing?)

I thought there might be a way to split up the line, while inside the dictionary loop, into individual elements, so that they could be displayed better… like maybe in table rows or a bullet list.

Most programming languages have a string split type of method, which would use a character as the delimiter. I realize that TW is not a programming language. But maybe it has something that can be used.

Something that would take this (a semi-colon delimited line)…

2;DollarTree;Cheetos

And turn it into variables that could be used in a dynamic scenario for display in a table, for instance…

| <thisPriority> | <thisContext> |<thisDescription> |

Or at the very least something like this…

| <split_1> | <split_2> |<split_3> |

(I realize I may have to switch to using html tags for the table elements, of course.)

RegEx that Uses Back References

Or maybe if TW can’t do a split, then can it use back references in RE to search the string and get the relevant data?

I also realize that Dictionary Tiddlers can be json format too. But while that does give me easy control of multiple attributes, it’s not easy to modify on the go.

Possible Example. It needs an HTML table because of the paragraph breaks inserted by the list widget. Or something.

<table padding=8>
<$list filter="[[2;DollarTree;Cheetos]]">
<$vars
thisPriority={{{[all[current]split[;]nth[1]]}}}
thisContext={{{[all[current]split[;]nth[2]]}}}
thisDescription={{{[all[current]split[;]nth[3]]}}}
>
<tr><td><<thisPriority>></td><td><<thisContext>></td><td><<thisDescription>></td></tr>
</$vars></$list>
</table>

Excellent! That works great.

One more tweak… I need to assign a css class on the table row based on the priority.

It a regular language, it might be something like…

thisPriorityClass="pri" + thisPriority;

so that my css rule could be something like…

.pri1 {
  color: red;
}
.pri2 {
  color: navy;
}