GetFirstLine [fully wikified] behavior in TW5?

132 views
Skip to first unread message

springer

unread,
Dec 22, 2019, 11:25:54 AM12/22/19
to tiddl...@googlegroups.com
Dear TiddlyWiki experts,

Post #2 in TW5 update "triage" mode... (coming to you with only the middle category of important problems that I do think are solvable, but not (at least on my own) quickly):

I need a glossary tiddler that includes only the first line for each term tagged "definition". (The full tiddler for each term often goes on to include examples, history, other associated data.) 

Here's how the glossary worked at my old site using ForEachTiddler :

<<forEachTiddler 
 where 
 'tiddler.tags.containsAny(["definition"])'
 sortBy
 "tiddler.title.toLowerCase()"
 ascending
 script
  '
   function getFirstLine(s) {
   var m = s.match(/\s*(.*)/);
   return m != null && m.length >= 1 ? m[1] : "";
   }
  ' 
 write
 '";[["+tiddler.title+"]]\n:{{green{"+getFirstLine(tiddler.text)+"}}}\n"'>>

What's the most straightforward way to translate this into TW5?

Any thoughts? Many thanks!!

Mark S.

unread,
Dec 22, 2019, 2:13:06 PM12/22/19
to TiddlyWiki
Here's an example that will get the first line of HelloThere at tiddlywiki.com

<$list filter="HelloThere +[get[text]splitregexp[\n]first[]]"/>

I'm not sure that parsing lines out of text is the best way to proceed. TW5 makes it easy to access tiddler fields. It might be better to put the line contents into their own fields. It would be helpful to know about the structure of your project.

Eric Shulman

unread,
Dec 22, 2019, 3:38:31 PM12/22/19
to tiddl...@googlegroups.com
On Sunday, December 22, 2019 at 8:25:54 AM UTC-8, springer wrote:
I need a glossary tiddler that includes only the first line for each term tagged "definition". (The full tiddler for each term often goes on to include examples, history, other associated data.) 

Here's how the glossary worked at my old site using ForEachTiddler :

<<forEachTiddler 
 where 
 'tiddler.tags.containsAny(["definition"])'
 sortBy
 "tiddler.title.toLowerCase()"
 ascending
 script
  '
   function getFirstLine(s) {
   var m = s.match(/\s*(.*)/);
   return m != null && m.length >= 1 ? m[1] : "";
   }
  ' 
 write
 '";[["+tiddler.title+"]]\n:{{green{"+getFirstLine(tiddler.text)+"}}}\n"'>>

What's the most straightforward way to translate this into TW5?

<$list filter="[tag[definition]sort[title]]">
   <$link />
<br>
   @@color:green; {{{ [
<currentTiddler>get[text]splitregexp[\n]first[]] }}}@@
</$list>

In TW5, the <$list> widget is the equivalent of the TWClassic "ForEachTiddler" macro

The filter shown above matches all tiddlers tagged with "definition" and sorts the resulting list by title (case-insensitive).

Then, within the list widget, for each tiddler that was found, it sets the <<currentTiddler>> value and:

* <$link /><br> outputs a line showing a link to the current tiddler

* @@color:green; ... @@ applies CSS syntax to set the text color

* {{{ ... }}} is an "inline list" that:
   1) gets the text of the current tiddler
   2) splits it into lines (using \n as the line boundary)
   3) outputs the first item in the "inline list" (i.e., the first line of the text from that tiddler)

Let me know how it goes...

enjoy,
-e

springer

unread,
Dec 22, 2019, 4:52:24 PM12/22/19
to TiddlyWiki
Mark,

Thanks for your reply... Of course, fields are a great way to structure data (I'm a database-nerd by mindset). At the moment, I'm trying to quickly whip a usable update into shape where there are over a hundred existing "flat" tiddlers where the first paragraph ("line") serves as a definition. Eventually, I might make templates and parse each item into field data such as definition, examples, synonyms, antonyms, etc., all with nice css bells and whistles. But the challenge now is just to get the site up and running. 

If you're curious, the glossary tiddler (currently bogged down with the full contents for each) is here:

springer

unread,
Dec 22, 2019, 5:04:58 PM12/22/19
to TiddlyWiki
Eric,

I'm quite sure that your work was at the core of most of what I achieved in TW Classic. I'm deeply grateful for that, and also appreciative that you're still so active in the community!

Something about the filtered list code in your reply is not *yet* coming out quite right (first impression: It isn't showing the titles, and looks as though some css styling is getting applied inappropriately, and isn't handling wikified text in the definition tiddlers properly), so there may be just a small typo, or something, that's not quite right? I'll poke around later. I'm quite sure I'll be able to troubleshoot it with another chunk of time. Thanks!

-Springer

On Sunday, December 22, 2019 at 3:38:31 PM UTC-5, Eric Shulman wrote:
On Sunday, December 22, 2019 at 8:25:54 AM UTC-8, springer wrote:
I need a glossary tiddler that includes only the first line for each term tagged "definition". (The full tiddler for each term often goes on to include examples, history, other associated data.) 

Here's how the glossary worked at my old site using ForEachTiddler :

<<forEachTiddler 
 where 
 'tiddler.tags.containsAny(["definition"])'
 sortBy
 "tiddler.title.toLowerCase()"
 ascending
 script
  '
   function getFirstLine(s) {
   var m = s.match(/\s*(.*)/);
   return m != null && m.length >= 1 ? m[1] : "";
   }
  ' 
 write
 '";[["+tiddler.title+"]]\n:{{green{"+getFirstLine(tiddler.text)+"}}}\n"'>>

What's the most straightforward way to translate this into TW5?

<$list filter="[tag[definition]sort[title]]">
   <$link />
<br>
   @@color:green; {{{ [
<currentTiddler>get[text]splitregexp[\n]first[]] }}}@@
</$list>

In TW5, the <$list> widget is the equivalent of the TWClassic "ForEachTiddler" macro...

TonyM

unread,
Dec 22, 2019, 5:06:58 PM12/22/19
to tiddl...@googlegroups.com
Springer

Depending on what you are trying to do a method I use may help,

Testing the text field for a prefix.


Get[text]prefix[https://]

this partial filer can for example identify Tiddlers containing a link pasted with ctrl V

Tony

TonyM

unread,
Dec 22, 2019, 5:33:28 PM12/22/19
to TiddlyWiki
All, some experiments inspired by this;

Extending this for fun I can extract a line/paragraph labeled "Abstract:"

<$list filter="HelloThere">
   <$list filter="[all[current]get[text]splitregexp[\n]prefix[Abstract:]]" variable=abstract>
       <$link to=<
<currentTiddler>> ><$text text=<<abstract>>/></$link>
   </$list>
</$list>

The above works on Tiddlywiki.com is HelloThere contains a line/paragraph
Abstract: Tiddler introducing Tiddlywiki features
anywhere in its text

This permits the development of simple parsing of tiddlers 

Simplified, you can also return only the abstract
<$list filter="HelloThere">
      <$link to=<
<currentTiddler>> ><$text text={{{ [all[current]get[text]splitregexp[\n]prefix[Abstract:]removeprefix[Abstract:]] }}}/></$link>
</$list>

Of course we can take this even further
  • Search each line eg for a #tag, Any word "splitregexp[ ]" with a prefix of # then display that line/paragraph for context.
  • A button that copies the abstract to a field called abstract - parse to field
Having fun? Me too.
Tony

springer

unread,
Dec 22, 2019, 7:21:25 PM12/22/19
to TiddlyWiki
Eric,

I'm able to get *almost* the right result with a variant on your suggestion, namely:

<$list filter="[tag[definition]sort[title]]">
''{{!!title}}'' <br>
   {{{[<currentTiddler>get[text]splitregexp[\n]first[]]}}}<br>
</$list>

Result here (I'll avoid editing for now): 

But the definition text itself is still turning into a link (to a non-existing tiddler), and of course doesn't wikify properly... 

On Sunday, December 22, 2019 at 3:38:31 PM UTC-5, Eric Shulman wrote:

Eric Shulman

unread,
Dec 22, 2019, 7:24:27 PM12/22/19
to TiddlyWiki
On Sunday, December 22, 2019 at 2:04:58 PM UTC-8, springer wrote:
I'm quite sure that your work was at the core of most of what I achieved in TW Classic. I'm deeply grateful for that, and also appreciative that you're still so active in the community!

Thanks!
 
Something about the filtered list code in your reply is not *yet* coming out quite right (first impression: It isn't showing the titles, and looks as though some css styling is getting applied inappropriately, and isn't handling wikified text in the definition tiddlers properly), so there may be just a small typo, or something, that's not quite right? I'll poke around later. I'm quite sure I'll be able to troubleshoot it with another chunk of time. Thanks!

* not sure why it doesn't show the titles (as links)
* the "get 1st line" code was returning the text as a link
* I didn't take into account that the line might have wiki syntax

Here's an updated bit of code that *should* address those problems:

<$list filter="[tag[definition]sort[title]]">
   <$link><$text text=<<currentTiddler>>/></$link><br>
   <$wikify name="firstline" text={{{ [
<currentTiddler>get[text]splitregexp[\n]first[]] }}}>
     
@@color:green; <<firstline>>@@<br>
   </$wikify>
</$list>

* the $link widget now explicitly specifies the display content instead of using the default
* the extracted first line of text is "wikified" (parsed) before being output

-e

springer

unread,
Dec 22, 2019, 7:33:51 PM12/22/19
to TiddlyWiki
Tony, this is promising, thanks!

In fact, I had started many definition tiddlers with ":" (because of the old ";" and ":" pattern for signaling term-definition pairs).

But your model works to search within a single specified tiddler, and replacing the outer filter to specify a tag as in <$list filter="[tag[definition]]"> is clearly not sufficient (It returns nothing, perhaps because "current" doesn't refer properly anymore?, and anyway we don't want the lines by themselves, but rather to have each definition paired with the title of the tiddler from which it comes)...

springer

unread,
Dec 22, 2019, 7:36:00 PM12/22/19
to tiddl...@googlegroups.com
Eric, yes. Hooray, and gratitude all over again! It looks nice, and can be used now.

HOWEVER, I realized there's still one useful aspect of wikification that isn't happening: links within the definition aren't rendering as links yet.

This is much of what made the original pretty exciting: if you're reading the entry for equivocation, which defines it as a kind of fallacy, you can see that "fallacy" itself is an available term and follow the link, right there from the glossary...

Can the links be restored as well?

TonyM

unread,
Dec 23, 2019, 7:01:01 AM12/23/19
to TiddlyWiki
Springer

Sorry, the filter tag[definition] was only partial. I just assumed you would have a proper filter according to your needs. E.g. [all[current]] etc...

Regards
Tony

springer

unread,
Dec 23, 2019, 7:37:27 AM12/23/19
to TiddlyWiki
Hi Tony,

Thanks for the reply. I admit that I'm cheating a bit with leaning on the group during the transition time because I need to get the website reliably functional asap (for teaching starting in January), and can come back to appreciating more of what's under the hood in the summer. I haven't properly learned my way around exactly what's different in TW5; it's a landscape where plenty is familiar, but some things are entirely different (in particular, everything that I used to accomplish with ForEachTiddler). Of course, I also knew the Classic site was burdened by its javascript reliance and seemed more and more like a dinosaur. Truly, I'm delighted at so much of what's possible in TW5. So, yes, I'm having fun! ;)

-Springer

springer

unread,
Dec 23, 2019, 7:45:34 AM12/23/19
to TiddlyWiki
Eric and all,

Might it still be possible to get the links within the definition blurbs to render as links, so that this compact glossary tiddler is richly weblike, as it was in Classic?

(I'm posting again because I realize that email shows only the initial version of my response to your fix, before I realized links were missing, and edited my response...)

-Springer

Mohammad

unread,
Dec 23, 2019, 11:57:30 AM12/23/19
to TiddlyWiki
Have you tried refnotes


It has a great glossary features and work both on mobile and desktop

--Mohammad

springer

unread,
Dec 23, 2019, 12:15:31 PM12/23/19
to TiddlyWiki
Mohammed,

Thanks, this looks very useful and interesting! 

It still seems (at least at first look?) not to support links *within* the glossary list text (or abbreviation table), but I look forward to exploring refnotes, since all of these functions are clearly helpful for academic purposes.

-Springer

Mohammad

unread,
Dec 23, 2019, 12:31:37 PM12/23/19
to tiddl...@googlegroups.com
Well,
 Here glossary are defined as a data tiddler (or one data tiddler per glossary set).
 Making link is not difficult but it shows all content in glossary table.

Your idea can be implemented to substitute data tiddler with ordinary tiddler,
then summary should be in a summary field and extended text in the text field (body)

--Mohammad
Reply all
Reply to author
Forward
0 new messages