Find current tiddle title with a javascript macro -or- regex transform {{!!title}}

41 views
Skip to first unread message

Leon Gomez

unread,
Sep 10, 2019, 9:18:22 PM9/10/19
to TiddlyWiki
Hello,
I'm trying to find a way to get the current {{!!title}} into an alphanumeric + underscores format variable, so for example "Topic: Foo Bar" would be converted to "topic_foo_bar"

The following works to convert text as wanted:

/*\
title: JavaC1
type: application/javascript
module-type: macro
\*/
(function(){

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

exports.name = "JavaC1";

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

/*
Run the macro
*/
exports.run = function(myText) {
if( !myText) myText = "all spaces to underscores";
        var myAlphanum = myText.replace(/[^A-Z0-9]+/ig, "_");
var output ="1: [" + myText + "] <br>2: [" + myAlphanum+ "]";
return output;
};

})();
Calling:
<<JavaC1>>
<<JavaC1 "symbols ? disappear ! as # well">>

but I can't find how to make it automatically retrieve {{!!title}} as with normal tiddlywiki macros.

Alternatively, is there any other method to transform/user regex inside regular macros, or easily acquire the title on that format? Thanks

Jeremy Ruston

unread,
Sep 11, 2019, 6:46:05 AM9/11/19
to tiddl...@googlegroups.com
Hi Leon

The usual way to address this would be to pass the tiddler title to the macro call by using the macrocall widget:

<$macrocall $name="JavaC1" myText={{!!title}}/>

That way, the macro can be used with any text, not just the current tiddler title.

Best wishes

Jeremy.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/346e7895-76fa-4d46-85a0-277504ee9b8f%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages