[TW5] parse and style a tiddler content

182 views
Skip to first unread message

paolo b

unread,
Jul 8, 2017, 7:56:11 AM7/8/17
to TiddlyWiki
Hi

I have the following problem:

a tiddler has a number of lines, each containing text formatted as follows:

         word: definition

I would like to apply a function to this tiddler so that
each definition gets hidden (e.g. as a tooltip or blanked) and a definition is revealed
only when moving over "word" - kind of a flashcard.

Further constraints:
The original tiddler should be preserved.
The function should be applicable to many, similarly formatted tiddlers.

Any advice on how to proceed will be greatly appreciated!

Paolo

Mark S.

unread,
Jul 8, 2017, 3:07:11 PM7/8/17
to TiddlyWiki
For some reason, Google isn't let me post my response.

Mark S.

unread,
Jul 8, 2017, 3:11:55 PM7/8/17
to TiddlyWiki
I didn't use any stylesheet stuff with this, though I imagine there are ways to approach it that would. I created the "tip" with span title="stuff"

If you create a data tiddler (be sure to mark it's type at the bottom of the tiddler) with this data and call it, for example, Quiz1 :

tiddler: the smallest semantic unit
field
:  a semantic unit smaller than a tiddler

And then set up these macros (perhaps globally):

\define getanswer() {{$(tiddler)$##$(question)$}}
\define makequiz(quiz)
<$vars tiddler="$quiz$">
<$list filter="[[$quiz$]] +[indexes[]]" variable="question">

<$wikify name="answer"  text=<<getanswer>> >
   
''Term'': <span title=<<answer>>>//<<question>>//</span>
   
</$wikify>
</
$list>
</$vars>
\end



Then you can create a list of terms based on Quiz1 by invoking like this:


<<makequiz "Quiz1">>

When you hover over a term, it's definition will pop up.

HTH
Mark



paolo b

unread,
Jul 11, 2017, 10:00:33 AM7/11/17
to TiddlyWiki
yes Mark, it did help - thanks.

I also defined a tooltip stylesheet so that I can style it as I like with:



<$wikify name="answer"  text=<<getanswer>> >
   <a  title=<<question>> class="tooltip"> <span title="">//<<answer>>//</span></a>


As a side effect, however, my original tiddler (now converted into data type) has lost its previous formatting.

Is there a way to avoid this, e.g. with a smarter transclusion, so that I can keep the original format??

Paolo

TonyM

unread,
Jul 14, 2017, 5:15:49 AM7/14/17
to TiddlyWiki
Paolo,

I may be off track but if you are trying to deal with what are effectively data tiddlers with content in the form   
word: definition

Then Tobias mentions how to

Iterate DataTiddler Indexes


https://tobibeer.github.io/tb5/#Iterate%20DataTiddler%20Indexes

That may contain some useful code

Regards
Tony

paolo b

unread,
Jul 14, 2017, 5:04:21 PM7/14/17
to TiddlyWiki
Hi  Tony

your suggestion is spot on, in fact I'm using a modified version of Tobias' approach.

The only remark I have is that the sort operator in

<$list filter="[<data>indexes[]sort[title]]">

appears to be superfluous, since

$:/core/modules/filters/indexes.js

already forces sorting according to the titles.

This was also a problem for me, since I wanted to list the data tiddler in its original order.
I've solved my problem by simply commenting

results.sort(); 
   
at the bottom of 

$:/core/modules/filters/indexes.js

On a different front, I've also managed to programmatically change the type
of the tiddler, so that it is temporarily set to data.
So I'm pretty happy now.

Regards

Paolo
Reply all
Reply to author
Forward
0 new messages