Hi, some time ago I came across a couple of macros by Ben Webber, contained in his “expand” plugin.
I use them really often and I like them, over time however, I realized that there is a limit that I would like to overcome.
But first it's perhaps best that I explain how it works:
As Ben Webber on his site puts it:
expand lets you define terms in text without breaking the flow. Readers can click the term to expand the definition at a sensible location. This allows the reader to select their desired level of detail.
Place a term, a word, to expand with expand.dt
and a definition in expand.dd
. If you click on the word you can make appear/disappear the definition. (The definition appears wherever you put the expand.dd
macro.)
<<expand.dt "Lorem">>
<<expand.dd "Lorem" " dolor sit amet">>
If you click on “Lorem” “dolor sit amet” appears next.
- There is a limit though: if I put quote marks in the definition the macro stops interprting the definition because it thinks the definition has already ended:
If I wanted to quote the word amet like this “amet” the macro would only dispaly as the definition of “Lorem”:
“dolor sit “
amet””
It wouldn’t be a big deal if this macro wasn’t so versatile
Indeed, I almost never use it for word definitions, but as a sort of on-demand display, since in place of the definition you can also put transclusions.
Unfortunately this only works with curly braces and not with the $transclude
widget, which is often better to use (or necessary if, for example, you had to specify the mode in which to transclude)
So my question is:
- Is it possible to make the macro recognize as “definition” text not necessarily contained in quote marks, but rather text encapsulated by another notation? (maybe two quote marks at the beginning and two at the end ““like this””)
I will add the code below, which I had slightly modified so that the functionality of the pulgin can be seen within a single tiddler (but still working in the same way).
I made a couple of other changes, like, for example, calling the two macros for convenience no longer expand.dt
and expand.dd
but ex-
and -pand
respectively.
- In a tiddler tagged with
$:/tags/Macro
:
\define expand.toggle()
<$list filter="[<stateTiddler>is[tiddler]]">
<$action-deletetiddler $tiddler=<<stateTiddler>> />
</$list>
<$list filter="[<stateTiddler>!is[tiddler]]">
<$action-createtiddler $basetitle=<<stateTiddler>> text="true" />
</$list>
\end
\define ex-(term, text, class)
\whitespace trim
<$vars stateTiddler=<<qualify "$:/state/plugins/benwebber/expand/$term$">>>
<$set name=text filter="[<__text__>is[blank]] +[then<__term__>else<__text__>]" select=0>
<$list filter="[<stateTiddler>is[tiddler]]" variable=null>
<$button class={{{ [<__class__>] expand-dd tw-border-none tw-cursor-pointer tw-decoration-dotted tw-m-0 tw-p-0 tw-underline hover:tw-decoration-solid +[!is[blank]join[ ]] }}} actions=<<expand.toggle>>>
<<text>>
</$button>
</$list>
<$list filter="[<stateTiddler>!is[tiddler]]" variable=null>
<$button class={{{ [<__class__>] expand-dd tw-bg-transparent tw-border-none tw-cursor-pointer tw-decoration-dotted tw-m-0 tw-p-0 tw-underline hover:tw-decoration-solid +[!is[blank]join[ ]] }}} actions=<<expand.toggle>>>
<<text>>
</$button>
</$list>
</$set>
</$vars>
\end
\define -pand(term, text, class)
\whitespace trim
<$vars stateTiddler=<<qualify "$:/state/plugins/benwebber/expand/$term$">>>
<!-- HACK: Preserve leading space (e.g., before a new sentence). -->
<$set name=space filter="[<__text__>prefix[ ]] +[then[ ]else[]]" select=0>
<$reveal type="nomatch" state=<<stateTiddler>> text="" class={{{ [<__class__>] expand-dt +[!is[blank]join[ ]] }}}>
<<space>><<__text__>>
</$reveal>
</$set>
</$vars>
\end