Can't call my JS macro

69 views
Skip to first unread message

Shareda

unread,
Oct 14, 2020, 2:52:40 PM10/14/20
to TiddlyWiki
Hello! What is wrong? I don't understand how to find out this and debug.

1. I created my macros tiddler;
2.  Added   $:/tags/Macro  tag;
3. Try to use these ways. It results just nothing.
  3.a. <<validateregexp "this||or that|">>
  3.b. <$macrocall $name="validateregexp" text="Text to be made into italics"/>
4. checked <<dumpvariables>>. There is no my macros...
Here is my macro exportred:

module-type: macro
tags: $:/tags/Macro
title: $:/hyperbook/validateregexp.js
type: application/javascript

/*\
title: $:/hyperbook/validateregexp.js
type: application/javascript
module-type: macro

Macro to return a clean regexp that does not hang-up the whole wiki and does not get out-of-memory 

\*/
(function(){

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

/*
Information about this macro
*/

exports.name = "validateregexp";

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

/*
Run the macro
*/
exports.run = function(regexp) {    
    regexp= str(regexp).replace(/([\|\\\{\}]){2,}/g, "$1");
    regexp= str(regexp).replace(/^([\|]){1,}/g, "");
    regexp= str(regexp).replace(/([\|]){1,}$/g, "");
    return regexp;
    // if(!baseName) {
// baseName = $tw.language.getString("DefaultNewTiddlerTitle");
// }
// return this.wiki.generateNewTitle(baseName, options);
};

})(); 

Felicia Crow

unread,
Oct 14, 2020, 5:45:54 PM10/14/20
to TiddlyWiki
Hi,

first question since it is a javascript macro: Have you reloaded your wiki after saving/importing the macro? Unlike wiki text macros javascript macros only get loaded in when the wiki itself is loaded.
The reason I am asking is because when I try to call your plugin after a reload it gives me a very clear error message of what is wrong: str is not defined.
Seeing how the input is already a string converting it to one - which I assume is what you wish to do - is not necessary. So if you just remove str() around each regexp you should be able to call your macro without problems.

Also as an aside: Javascript macros are global by default and don't need to be tagged with $:/tags/Macro.

Hope this helps.
Felicia

Shareda

unread,
Oct 15, 2020, 12:30:45 AM10/15/20
to TiddlyWiki
Felicia, Yes, I've reloaded wiki after saving/importing the macro. But there was no error message or I just don't know where(?) to look for it. Anyway, I removed str(), and macros is ok now! So thank you! I did not know about that error! Now I remove $:/tags/Macro..

четверг, 15 октября 2020 г. в 03:45:54 UTC+6, Felicia Crow:

Felicia Crow

unread,
Oct 15, 2020, 9:20:51 AM10/15/20
to TiddlyWiki
Hi,

strange then. Here is what I get when I try to save a tiddler that calls your macro - before removing str() - right in the middle of the screen:


But as long as it works now just a strange occurrence, glad that I could help.
Reply all
Reply to author
Forward
0 new messages