TW5 - Macro result gets wikified

84 views
Skip to first unread message

Danielo Rodríguez

unread,
Oct 15, 2015, 5:37:44 PM10/15/15
to TiddlyWikiDev
Hello everyone,

I  have a simple macro that returns me a file name without path for a given full path file name. The problem is that, some results are getting wikified.
This is a big problem because I want to use the result of the macro as the text of a button. But instead of firing the button, it is navigating to the camel case title.

Here is the macro code (very simple!)

/*\
title: daMacro
type: application/javascript
module-type: macro


Macro that removes the path part of an absolute filename
\*/

(function(){


   
/*jslint node: true, browser: true */
   
/*global $tw: false */
   
"use strict";


   
/*
     Information about this macro
     */



    exports
.name = "removepath";


    exports
.params = [{name:"filename"}];


   
/*
     Run the macro
     */

    exports
.run = function(filename) {
       
return filename.substr(filename.lastIndexOf('/')+1);
   
};


})();

An invocation example

<$macrocall $name="removepath" filename="path/to/GettingStarted.tid"/>

Regards

Eric Shulman

unread,
Oct 15, 2015, 10:26:23 PM10/15/15
to TiddlyWikiDev
On Thursday, October 15, 2015 at 2:37:44 PM UTC-7, Danielo Rodríguez wrote:
I  have a simple macro that returns me a file name without path for a given full path file name. The problem is that, some results are getting wikified.
This is a big problem because I want to use the result of the macro as the text of a button. But instead of firing the button, it is navigating to the camel case title.

If you use <$text text=...> to render the macro results as a button label, then it won't get wikified.

So, instead of:
   <$macrocall $name="removepath" filename="path/to/GettingStarted.tid"/>
try this:
   <$text text=<<removepath filename:"path/to/GettingStarted.tid">>/>

enjoy,
-e
Eric Shulman
ELS Design Studios
TiddlyTools - "Small Tools for Big Ideas!"
InsideTiddlyWiki: The Missing Manuals

YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:



Danielo Rodríguez

unread,
Oct 16, 2015, 4:12:10 AM10/16/15
to TiddlyWikiDev
If you use <$text text=...> to render the macro results as a button label, then it won't get wikified.

I totally forgot about the text widget. 


 
So, instead of:
   <$macrocall $name="removepath" filename="path/to/GettingStarted.tid"/>
try this:
   <$text text=<<removepath filename:"path/to/GettingStarted.tid">>/>

I have to use the macro-call widget because I'm not passing the parameter as a fixed string. I'm using the <<currentTiddler>> variable as input of the macro. Is there any other way I can do it? Maybe I can mimic the behavior of the text widget?

BJ

unread,
Oct 16, 2015, 2:00:25 PM10/16/15
to TiddlyWikiDev

like this:

<$macrocall $name="removepath" filename="path/to/GettingStarted.tid" $type="text/plain"/>

BJ

Tobias Beer

unread,
Oct 16, 2015, 4:53:33 PM10/16/15
to TiddlyWikiDev
Hi Danielo,
 
I have to use the macro-call widget because I'm not passing the parameter as a fixed string. I'm using the <<currentTiddler>> variable as input of the macro. Is there any other way I can do it? Maybe I can mimic the behavior of the text widget?

I think, perhaps a bit annoyingly so, the way to go is to use a variable and not a parameter...

<$vars filename=<<currentTiddler>>><$text text=<<removepath>>/></$vars>

...and then read that variable in your macro.

Not sure, but then you could probably also do...

<$vars filename=<<currentTiddler>>>
<$set name="fancy" filter="[
<removepath>removesuffix[.tid]">
with: <
<fancy>>
</$set>
</$vars>

Best wishes,

— tb

Danielo Rodríguez

unread,
Oct 18, 2015, 12:53:59 PM10/18/15
to TiddlyWikiDev


El viernes, 16 de octubre de 2015, 20:00:25 (UTC+2), BJ escribió:

like this:

<$macrocall $name="removepath" filename="path/to/GettingStarted.tid" $type="text/plain"/>

Hello BJ,

You gave me the clue! What I was looking for is $output="text/plain". The $type stuff renders the output like it were inside back-ticks (`) 
Cool!!

Danielo Rodríguez

unread,
Oct 18, 2015, 12:56:46 PM10/18/15
to TiddlyWikiDev
I think, perhaps a bit annoyingly so, the way to go is to use a variable and not a parameter...

<$vars filename=<<currentTiddler>>><$text text=<<removepath>>/></$vars>

Yes, a bit annoyingly. I'm not a fan of using this kind of solution. It tends to be spaghetti code. It's hard to read because you don't know exactly from where is coming the variable you are using and it is, in general very confusing.

Thanks in any way for taking the time to answering me
Reply all
Reply to author
Forward
0 new messages