Search and find headings in a tiddler using TW 5.1.20 core features

84 views
Skip to first unread message

Mohammad

unread,
Aug 22, 2019, 8:02:22 AM8/22/19
to tiddl...@googlegroups.com
With the new features like match and improved search in Tiddlywiki 5 who can I search and list all headings in a Tiddler?

I mean, If I have a tiddler with a text like below

!h1-1
text
...

!h2-1
text
...


!h1-2
text
...

!h2-2
text
....

!h3-2
text
...

etc


How a simple filter can return

  • h1-1
  • h2-1
  • h1-2
  • h2-2
  • h3-2

I know there is plugins to do this for example those by Tobias Beer, but I want to only use the core features of TW  5.1.20
--Mohammad



Mat

unread,
Aug 22, 2019, 12:23:45 PM8/22/19
to TiddlyWiki
\define extract()
<$list filter="$(t)$ +[splitregexp[!]prefix[h]]">

</$list>
\end

<$set filter="[[mytid]get[text]]" name=t>
<<extract>>
</
$set>


<:-)

Mat

unread,
Aug 22, 2019, 12:25:14 PM8/22/19
to TiddlyWiki
Ah, you should probably make those quote triple quotes since you're get'ing the whole text which could contain single quotes.

<:-)

Mat

unread,
Aug 22, 2019, 12:29:32 PM8/22/19
to TiddlyWiki
Somewhat slimmer

\define extract()
<$list filter="""$(t)$ +[splitregexp[!]prefix[h]]""">

<
/$list>
\end

<$set value={{mytid}} name=t>
<<extract>>
</
$set>

<:-)

Mohammad

unread,
Aug 22, 2019, 12:50:03 PM8/22/19
to TiddlyWiki
Thank Mat that works!

Another question, If I mean by h1 and h2 and h3, heading 1 and 2 and 3 like

! some text
!! some text
!!some text


How the filter shall be revised to cover this new form?

Mat

unread,
Aug 22, 2019, 1:46:23 PM8/22/19
to TiddlyWiki
Somewhat to my surprise this turned out to be very concise:

<$list filter="""[{mytid}split[
]prefix[!]splitregexp[!]]""">

</$list>

(Yes, that line break in the middle of the split brackets should be there.)

<:-)

Mohammad

unread,
Aug 22, 2019, 2:31:04 PM8/22/19
to TiddlyWiki
This is really amazing!

A KISS solution :-)

Mohammad

unread,
Aug 22, 2019, 2:33:19 PM8/22/19
to TiddlyWiki
Mat you match the line breaks that way! Very smart solution!

So, no matter which browser I use because you did not use \n

Am I right?

--Mohammad

Mohammad

unread,
Aug 22, 2019, 2:36:48 PM8/22/19
to TiddlyWiki
one small issue:
You know both of below lines works as valid wikitext

!  heading one
   
!  another heading one


The second line cases the filter does not match heading

--Mohammad

Mohammad

unread,
Aug 22, 2019, 2:39:01 PM8/22/19
to TiddlyWiki
What do you think if we use trim[]?

--Mohammad

Mat

unread,
Aug 22, 2019, 3:17:11 PM8/22/19
to TiddlyWiki
I learnt the "split[
]" trick several years ago from someone, possibly PMario.

Trim seems to work, yes.

Also, there should be a removal of blanks. So result is:

<$list filter="""[{mytid}split[
]trim[]prefix[!]splitregexp[!]!is[blank]]""">

</$list>

<:-)

Mohammad

unread,
Aug 22, 2019, 3:37:54 PM8/22/19
to TiddlyWiki
Added to TW-Scripts.

Thank you Mat! I love this short and Smart solution!

I will use this as a macro to create small TOC for long tiddlers! Of course it is not clickable but very useful to show what is discussed at a glance.

--Mohammad

Mat

unread,
Aug 22, 2019, 4:44:04 PM8/22/19
to TiddlyWiki
You can actually make the titles clickable, especially if it is for a single long tiddler, even if it not a perfect solution:


<:-)

Mohammad

unread,
Aug 22, 2019, 5:15:00 PM8/22/19
to TiddlyWiki
Thanks for the reference!

Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages