Convert the output of a variable to plain text

146 views
Skip to first unread message

kebi

unread,
Aug 10, 2020, 9:21:15 PM8/10/20
to tiddl...@googlegroups.com
Hello guys, I'm trying to recall a macro with a reference field using the following code

<$macrocall $name="rememberq" id=<<currentTiddler>>

question="Q"
answer="A"

reference=<<stream-root-title>>/>

The problem is that the reference field only supports plain text and <<stream-root-title>> seems to be returning something else
Here's the declaration of <<stream-root-title>>:

<$vars stream-root-title=<<currentTiddler>>
    contextmenu-state=<<qualify "$:/state/sq-context-popup/">>
    row-edit-state=<<qualify "$:/state/sq/streams/current-edit-tiddler">>
    drag-title-state=<<qualify "$:/state/sq/streams/current-drag-title">>
    drag-title-nextsibling-state=<<qualify "$:/state/sq/streams/current-drag-nextsibling">>
    >
<div class={{{ stream-root [{$:/state/sq/nodes/global-drag-state}match[yes]then[stream-dragactive]] [<currentTiddler>!has[stream-list]then[stream-newlist]] +[join[ ]] }}}>
        <$macrocall $name="stream"/>
</div>
</$vars>

\define stream()
\whitespace trim
<div class="stream-list">
    <$vars dropTargetTiddler=<<currentTiddler>> >
        <$list filter="[list[!!stream-list]!is[missing]]">
        <$set name="enable-dnd" filter="[<enable-dnd>match[no]] ~[<drag-title-state>get[text]match<currentTiddler>then[no]]" select="0">
            <<stream-row-template>>
        </$set>
        </$list>
        <$tiddler tiddler="">
            <!-- to drop after the last child of any list level-->
            <$droppable actions=<<stream-drop-actions>> tag="div" enable=<<enable-dnd>> class="stream-droppable">
                <div class="tc-droppable-placeholder">
                &nbsp;
                </div><!-- idea only want below div with height when its a child with no more children-->
                <$list filter="[<currentTiddler>!has[stream-list]]" variable="_NULL"><div class="stream-droppable-spacer"/></$list>
            </$droppable>
        </$tiddler>
        <$list filter="[all[current]match<stream-root-title>]" variable="_NULL">
            <!-- if we are the root, add a button to add more nodes-->
            <div class="stream-row">
                <div class="stream-node-control stream-node-control-addnew">
                    <div class="stream-node-collapser">
                    </div>
                    <div class="stream-node-handle-wrapper">
                        <$button tag="div" class="tc-btn-invisible" tooltip="add node" actions=<<add-node-actions>> >
                            {{$:/plugins/sq/streams/icons/new-node-btn}}
                        </$button>
                    </div>
                </div>
                <div class="stream-node-block">
                    <!--consider moving last child dropzone in here, though thats for children too-->
                </div>
            </div>               
            <$set name="currentTiddler" filter={{{[<contextmenu-state>get[current]]}}}>
                {{||$:/plugins/sq/streams/contextmenu/contextmenu-template}}
            </$set>
        </$list>
    </$vars>
</div>
\end
 
 Is there a way I can convert the output of <<stream-root-title>> to plain text?

kebi

unread,
Aug 10, 2020, 9:30:05 PM8/10/20
to TiddlyWiki
If I use this it works, so I think it is just a formatting problem
 
\define myMacro()
Reference text
\end

<$macrocall $name="rememberq" id=<<currentTiddler>>

question="Q"
answer="A"

reference=<<myMacro>>/>

 

Eric Shulman

unread,
Aug 10, 2020, 9:51:52 PM8/10/20
to TiddlyWiki
On Monday, August 10, 2020 at 6:21:15 PM UTC-7, kebi wrote:
Hello guys, I'm trying to recall a macro with a reference field using the following code

<$macrocall $name="rememberq" id=<<currentTiddler>> question="Q" answer="A" reference=<<stream-root-title>>/>

The problem is that the reference field only supports plain text and <<stream-root-title>> seems to be returning something else
Here's the declaration of <<stream-root-title>>:

<$vars stream-root-title=<<currentTiddler>>   ...   >
...
 Is there a way I can convert the output of <<stream-root-title>> to plain text?

According to the code you posted, "stream-root-title" is supposed to be the title of a tiddler, so it should work just fine as a parameter for your macro call.

Also, a macro is simply a text substitution process, so whatever you define in a macro is simply inserted into the "calling" location (i.e., the parameter value).

In any case, to address your question: how to convert the output of a macro call like <<foo>> into plain text...

Let's suppose you have a macro that uses the <$list> widget to output a set of tiddler names based on a tag value:
\define getList(tag)
<$list filter="[tag[$tag$]]"> <<currentTiddler>> </$list>
\end

Then writing something like:
<$macrocall $name="something" list=<<getList "foo">> />
will NOT work, because the output of the "getList" macro is the actual <$list>...</$list> code.

To use the *results* of the macro as plain text, you can use the <$wikify> widget, like this:
<$wikify name="listResults" text=<<getList "foo">> >
   <$macrocall $name="something" list=<
<listResults>> />  
</$wikify>
Within the <$wikify>...</$wikify>, you can use the named variable (i.e, "listResults").

Hopefully, the above explanation doesn't cause too much confusion and helps you to resolve your problem...

Let me know how it goes...

enjoy,
-e

 

kebi

unread,
Aug 10, 2020, 10:00:44 PM8/10/20
to TiddlyWiki
Eric thanks so much for the detailed explanation, however the macro "rememberq" doesn't seem to process the reference <<stream-root-title>> correctly.
Here's the code

\define rememberq(id, question, answer, reference: "")
    <div class="rememberq">
        <div class="rquestion">
            <div>Q:</div>
            <p>$question$</p>
        </div>
        <div class="ranswer">
            <div>A:</div>
            <p>$answer$</p>
        </div>
        <div class="tr-selfidentification">
            <$set name="selfid" filter="""[enlist[$reference$]]""" value="""[<$link to="$reference$">$reference$</$link>: $id$]""" emptyValue="[$id$]">
                <<selfid>>
            </$set>
        </div>
        <div class="rid">
            [$id$]
        </div>
        <div class="tr-reference">
            <$text text=<<__reference__>>/>
        </div>
    </div>
\end

 for some reason <$text text=<<__reference__>>/> doesn't return the title I'm looking for.

Eric Shulman

unread,
Aug 10, 2020, 10:34:03 PM8/10/20
to TiddlyWiki
On Monday, August 10, 2020 at 7:00:44 PM UTC-7, kebi wrote:
Eric thanks so much for the detailed explanation, however the macro "rememberq" doesn't seem to process the reference <<stream-root-title>> correctly.
for some reason <$text text=<<__reference__>>/> doesn't return the title I'm looking for.

In your first message, you showed:
<$vars stream-root-title=<<currentTiddler>>
    contextmenu-state=<
<qualify "$:/state/sq-context-popup/">>
    row-edit-state=<
<qualify "$:/state/sq/streams/current-edit-tiddler">>
    drag-title-state=<
<qualify "$:/state/sq/streams/current-drag-title">>
    drag-title-nextsibling-state=<
<qualify "$:/state/sq/streams/current-drag-nextsibling">>
    >
<div class={{{ stream-root [{$:/state/sq/nodes/global-drag-state}match[yes]then[stream-dragactive]] [
<currentTiddler>!has[stream-list]then[stream-newlist]] +[join[ ]] }}}>
        <$macrocall $name="stream"/>
</div>
</$vars>

In the above code, the value of "stream-root-title" is only valid within the scope of the <$vars>...</$vars>.

However, it would seem that your invocation of the "rememberq" macro is *outside* of the <$vars>...</$vars>.
Thus, the value of stream-root-title would not be defined at that time.

Try using something like: reference=<<currentTiddler>>, and see if that helps.

-e

 

kebi

unread,
Aug 10, 2020, 10:42:48 PM8/10/20
to tiddl...@googlegroups.com
Thanks for the reply!

Unfurtunately <<currentTiddler>> returns a different text from <<stream-node-title>> but I found a solution by printing <<stream-node-title>> directly into the reference field.

\define getMacro()

<$macrocall $name="rememberq" id=<<currentTiddler>>

question=""
answer=""

reference="$(nodetitle)$"/>
\end

<$set name=nodetitle
      value=<<stream-root-title>> >
    <$action-sendmessage
        $message="tm-edit-text-operation"
        $param="replace-selection"
        text=<<getMacro>>
    />
</$set>
 
 Thank you so much for your help Eric!

TW Tones

unread,
Aug 11, 2020, 1:19:37 AM8/11/20
to TiddlyWiki
Kebi,

Without looking at you code, most more complex macros will retun a result as wiki text macros
`<<macroname>>` but if you wish to use it in a filter or subsequent calculations you need to wikify it.

I have developed a few personal runels to help
  • Wikify at the last possible moment
  • Its ok to reuse the variable name

\define macroname() bla bla

Or a
<$set name=macroname filter="a filter"> etc...


<$wikify name=macroname text="<<macroname>>" output=text>

In here a filter [<macroname>match[test]] will work as expected and <<macroname>> should return a simple value, but it may be further wikified during the final render of the tiddler so if you used <$link to=<<macroname>> /> it should work.

</
$wikify>

I would like a shortcut to using the wikify widget as above.

Regards
Tony

kebi

unread,
Aug 11, 2020, 9:27:47 AM8/11/20
to TiddlyWiki
Thanks Tony for the wikify example, but unfortunately it didn't work as well. Thanks for the info though!

TW Tones

unread,
Aug 11, 2020, 9:09:55 PM8/11/20
to TiddlyWiki
Kebi,

Sorry to hear. I find this a little fragile. I have it working myself so I am not sure what is occurring.

The following was tested on tiddlywiki.com and somewhat demonstrates a few ways to make use of it.

If your macro is defined elsewhere and more complex you may need to use \whitespace trim, the text widget in my example will show unwanted spaces in the result if this is occurring.

\define macroname() test

<$wikify name=macroname text="<<macroname>>" output=text>

{{{ [<macroname>match[test]then[Matches]] }}}

<$list filter="[<macroname>match[test]then[Matchesinfilter]]"><<currentTiddler>></$list>

'<$text text=<<macroname>>/>'

</$wikify>


Regards
Tones

kebi

unread,
Aug 12, 2020, 4:46:41 AM8/12/20
to TiddlyWiki
The wikify method itselft works, I think I'm note getting the correct output from <<stream-root-title>> because of some loop caused by the plugin that defines it.

Saq Imtiaz

unread,
Aug 12, 2020, 8:31:47 AM8/12/20
to TiddlyWiki
@Eric as I understand it, the rememberq macro is part of an editor toolbar button. So likely scope is the problem.

For most purpose storyTiddler should have the same value as stream-root-title unless you're showing a stream inside a modal or a new window.

@kebi If this still doesn't help, please post your file to facilitate debugging.

Cheers,
Saq
Reply all
Reply to author
Forward
0 new messages