[TW5] Filter output "format" is either links or string - that's a problem!

226 views
Skip to first unread message

Mat

unread,
Apr 1, 2016, 3:56:44 AM4/1/16
to TiddlyWiki
Problem illustrated as minimal test case:

Put this in first tiddler:

title: tid
text
: aaa bbb ccc

and then this in another tiddler;

Original string (i.e the text in tid): {{tid}}<br>
<$set name="prefix_aaa" filter="[[tid]get[text]splitbefore[aaa]]">
<$set name="prefix_bbb" filter="[[tid]get[text]splitbefore[bbb]]">
prefix_aaa
: <<prefix_aaa>> (string!) <br>
prefix_bbb
: <<prefix_bbb>> ("title"!)<br>

<$set name="mystring_aaa" filter="[[tid]get[text]splitbefore<prefix_aaa>]">
<$set name="mystring_bbb" filter="[[tid]get[text]splitbefore<prefix_bbb>]">
mystring_aaa
: <<mystring_aaa>> - the original string is splitbefore the prefix<br>
mystring_bbb
: <<mystring_bbb>> - the original string is NOT splitbefore the prefix`

</$set>
</$set>
</$set>
</$set>


As seen in the prefixes, the filter output "format" differs depending on if the string contains spaces or not. AFAICT the behaviour is inconsistent or at least not sensible and has caused problems for me many times in trying to work with strings.

My first question if I'm simply approaching it the wrong way and if soeone has a working (general) solution?

If not, then I hope to post a git issue about this but I wonder what the best solution proposal would be;

I see a need for both title links as output and plain strings as output, so I'm thinking the best proposal would be for a filter operator ( string[] ) or perhaps a listwidget parameter that specifies output format ( format="string" ). Which would be better? Other ideas?

Thanks!

<:-)

Jeremy Ruston

unread,
Apr 1, 2016, 3:59:54 AM4/1/16
to TiddlyWiki
Hi Mat

All you're seeing here is the quoting rules that TiddlyWiki uses for lists; the result of <$set filter> is a list; by design. I suspect that sometimes what you actually want is to access the first element of the list as a single item, without the list quoting. That's something that the <$set filter> widget could  be extended to do.

Best wishes

Jeremy.


--
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+...@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/b65dd8ea-ce7c-41c0-ab01-719c6d90018a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Mat

unread,
Apr 1, 2016, 4:38:49 AM4/1/16
to TiddlyWiki, jeremy...@gmail.com
Jeremy, thanks for super fast reply!!!


All you're seeing here is the quoting rules that TiddlyWiki uses for lists; the result of <$set filter> is a list; by design.

Aha, so the SetWidget "remakes" the filter output (which is originally a set of tiddlers) into a list. That's interesting.


I suspect that sometimes what you actually want is to access the first element of the list as a single item, without the list quoting.

Just to make sure; IF one would want any other element than particularly the first one, this could then be controlled in the filter (using nth), right?

 
That's something that the <$set filter> widget could  be extended to do.

That would be very useful and it would much simplify manipulation of strings and tiddler content. Should I post an issue?

Thank you!

<:-)

Jeremy Ruston

unread,
Apr 1, 2016, 6:54:02 AM4/1/16
to Mat, TiddlyWiki
Hi Mat

Aha, so the SetWidget "remakes" the filter output (which is originally a set of tiddlers) into a list. That's interesting.

No. The output of the filter is a list. The standard TiddlyWiki way of storing a list as a string is to quote the entries in the list with spaces. There’s no “remaking” that I can see.

I suspect that sometimes what you actually want is to access the first element of the list as a single item, without the list quoting.

Just to make sure; IF one would want any other element than particularly the first one, this could then be controlled in the filter (using nth), right?

Correct.

That's something that the <$set filter> widget could  be extended to do.

That would be very useful and it would much simplify manipulation of strings and tiddler content. Should I post an issue?

Perhaps “Extend <$set> widget to allow saving filter results as a single entry”?

Best wishes

Jeremy


Thank you!

<:-)

c pa

unread,
Apr 1, 2016, 2:15:09 PM4/1/16
to TiddlyWiki, matia...@gmail.com
You can use $list instead of set
Paste this into your tiddler and you get one item at a time:

<$list variable="first" filter="[list[tid!!text]first[]]">
     <<first>>
</$list>

<$list variable="second" filter="[list[tid!!text]nth[2]]">
     <<second>>
</$list>

<$list variable="third" filter="[list[tid!!text]nth[3]]">
     <<third>>
</$list>

Reply all
Reply to author
Forward
0 new messages