How to get the count of italiced words in the tiddler text field of markdown format

As the title says, what is the filter needed to get the count of italiced words in the tiddler text field while using markdown format.

I am using __itallics__ syntax for italics in markdown format

Intuition tells me that such a thing does not exist in tiddlywiki

But this might be possible by writing a markdownit plugin

I was thinking regexp or search operator and count operator might be able to do it. But I was not able to put together a filter expression for doing it

I am confident it can be done with TiddlyWiki functions and script. I will experiment to find a way, however do you want a count of words or a count of underlines eg This __and that__ is two __sections__ of underline but three underlined words. Can we assume the text field will not start with or end in __ ?

I need the count of underlines , not the count of underlined words.
Thanks @TW_Tones for taking a look at this

yes

Lets say the tiddler underlined contains;

Sample data __with this__ and __that__,

__or this__
Then that 

Now we have the function

\function underlines(tiddler) [<tiddler>get[text]split[__]count[]subtract[1]divide[2]]

then call it;

<<underlines underlined>>

We get 3.
We need two __ for each section, that why we divide by 2, but the split process will generate one more “piece” than we need so subtract by one.

  • We assume the text field will not start with or end in __, which is reasonable.
1 Like

Thank you @TW_Tones
It should be like this rite ?

\function underlines(tiddler) [<tiddler>get[text]split[__]count[]divide[2]subtract[1]]

No. Tony’s formula is right. If you test this filter in Advanced search: [[__test__]split[__]count[]]. You’ll see that it returns “3” because of the split operation, you’ll always get 1 section more than there are underscores.

So first -1 than /2 should be right.

@TW_Tones @pmario
Here is a demo of the two variants of function to count underlines in tiddler text field.
I am getting the correct answer when i do the division before subtraction.

In the demo you have the function code and the text in the same tiddler.

So you also count the 1 underscore, which is part of the function and therefore is a “false positive”, which should not be counted.

So having the function code in the same tiddler is technically not the right approach. It is way to brittle. If you add a second “test” function into that tiddler you will count 2 false positives. … and so on

1 Like