Is there a filter to find links in other fields than text

144 views
Skip to first unread message

Jan

unread,
Jul 14, 2019, 5:50:10 AM7/14/19
to TiddlyWiki
Hello,
I would like to detect links in a field with quite a lot of text which
is called "dialogue". Is there a smart filter-spell for that.
The ideas I had so far to solve this problem are very complicated.

Best wishes and thanks for your help!
Jan

Mat

unread,
Jul 14, 2019, 6:01:39 AM7/14/19
to TiddlyWiki
Find links in general or find specific links?

The former is more complicated but as a smallest requirement it would probably demand that links are enclosed in [[brackets]], i.e not camelcase.... or else it would probably be veeery tricky to find them.

If it is merely a question of finding specific links in a field then you can use the search filter operator.

<:-)

Mat

unread,
Jul 14, 2019, 6:03:44 AM7/14/19
to TiddlyWiki
>or else it would probably be veeery tricky to find them.

Pah! I'm exaggerating. It is "just" a matter of creating the right regexp for it. Not that I could do it.

<:-)

Jan

unread,
Jul 14, 2019, 6:26:33 AM7/14/19
to tiddl...@googlegroups.com
Hi Mark
thanks for the clarification, it would be nice if the filter could detect all links sourrounded by double brackets.
-Jan

PS:
It would be great if the LinksOperator hat a field parameter...
--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/ebad32fa-60c1-4434-a943-350812eb47d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan

unread,
Jul 14, 2019, 6:51:37 AM7/14/19
to tiddl...@googlegroups.com
Hi Mat,
Unfortunately filtersyntax gets so terribly complicated when the param contains squarebrackets.
This here causes a syntax error: [!is[system]regexp[/\[.*?\]/g]]

And how do I enter the suffix for the field?
-Jan





Am 14.07.2019 um 12:03 schrieb Mat:

Mohammad

unread,
Jul 14, 2019, 12:23:59 PM7/14/19
to TiddlyWiki
Jan,
 Have you tried the find macro! It easily find such cases!
The find macro actually find patterns and return the content!

-Mohammad


On Sunday, July 14, 2019 at 2:56:33 PM UTC+4:30, Jan wrote:
Hi Mark
thanks for the clarification, it would be nice if the filter could detect all links sourrounded by double brackets.
-Jan

PS:
It would be great if the LinksOperator hat a field parameter...


Am 14.07.2019 um 12:03 schrieb Mat:
>or else it would probably be veeery tricky to find them.

Pah! I'm exaggerating. It is "just" a matter of creating the right regexp for it. Not that I could do it.

<:-)
--
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 tiddl...@googlegroups.com.

Mark S.

unread,
Jul 14, 2019, 12:51:42 PM7/14/19
to TiddlyWiki
You need to put your expression in a separate variable:

<$vars reg="(?g)\[\[.*?\]\]">
<$list filter="[!is[system]regexp:myfield<reg>]"/>
</$vars>

I tested using field "myfield". I was surprised to find that there actually is a matching field at tiddlywiki.com.

Note that the regexp filter has its own notation for indicating a global search. I put it in, but don't really understand what use it has, since it is the tiddler that gets returned, not the field. So finding one match should be good enough.


On Sunday, July 14, 2019 at 3:51:37 AM UTC-7, Jan wrote:
Hi Mat,
Unfortunately filtersyntax gets so terribly complicated when the param contains squarebrackets.
This here causes a syntax error: [!is[system]regexp[/\[.*?\]/g]]

And how do I enter the suffix for the field?
-Jan




Am 14.07.2019 um 12:03 schrieb Mat:
>or else it would probably be veeery tricky to find them.

Pah! I'm exaggerating. It is "just" a matter of creating the right regexp for it. Not that I could do it.

<:-)
--
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 tiddl...@googlegroups.com.

Mohammad

unread,
Jul 14, 2019, 1:18:53 PM7/14/19
to TiddlyWiki
Hi Mark,
 I was surprised with this simple and elegant solution you proposed albeit the regxp is behind my knowledge! :-)

Added to TW-Scripts.

Cheers
Mohammad

Jan Johannpeter

unread,
Jul 14, 2019, 4:52:14 PM7/14/19
to tiddl...@googlegroups.com
Hi Mark,
 thanks, again you saved my day! 
I will implement this at once!
Jan

To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Jan

unread,
Jul 15, 2019, 7:06:31 AM7/15/19
to TiddlyWiki
Hi,
alas the Find-Macro and also the Extract-Macro fail in this job. This really seems to be an issue for a widget which can escape the square-bracket-problem.

I made a quick attempt to solve this problem with a widget matching for the css, with no success so far.
/*\
title: $:/core/modules/macros/roles.js
type: application/javascript
module-type: macro
Making some replacements in Textinputs
\*/

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

/*
Information about this macro
*/
  exports.name = 'roles';
  exports.params = [{ name: 'text'  }];
/*
Run the macro
*/
exports.run = function(text) {
      text = text.match("/\[.*?\]/g");
      return text
} ;
})();

Seeing how complicated this problem is in wikitext, I think it would be usefull, to have such a thing as "Extract Links Widget".

Jan






Jan

Am 15.07.2019 um 10:01 schrieb Jan:
Hi Mark!
I have tried out your proposition but alas, the filter is not working the way I would like it to work:
So far it looks for Tiddlers that have the field "myfield", it should look for Links in this field.

I have tired several variations with get[] and list[] to have the dialoguebut it nearly seems impossible to filter the result for [[square brackets.

Jan

TonyM

unread,
Jul 15, 2019, 7:28:12 AM7/15/19
to TiddlyWiki
This is part of the render process already.

Perhaps it just needs a method to access it. 

Jeremy is talking about opening more of the core features to user config.

See Control Panel > Infor > Advanced > Parsing > wikilink 

Here you can enable and disable it for text fields. This may help you identify how it is done for the text field and redeploy this on other fields.

Regards
Tony

Jan

unread,
Jul 15, 2019, 8:42:39 AM7/15/19
to tiddl...@googlegroups.com
AFAIK the widget is applied before the Links are rendered when I call it like that.

<div class="roles">

<$macrocall $name="roles" text={{!!dialogue}}/>

</div>

So the input does not seem to be the problem - it is the widget.
Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Jan

unread,
Jul 15, 2019, 10:12:22 AM7/15/19
to tiddl...@googlegroups.com

Mark S.

unread,
Jul 15, 2019, 10:51:25 AM7/15/19
to TiddlyWiki
With the reg expression text previously mentioned, and the regexps (reg expression string extractor) in PR 2963
 it should be possible to extract links designated with [[ and ]] .

Jan

unread,
Jul 15, 2019, 3:45:42 PM7/15/19
to tiddl...@googlegroups.com
Hi Mark, that looks great, is this already available?
Meanwhile I created a solution which is working quit good but has one flaw which I would like to eliminate:
[[Mr. Test]] Gets parsed [[Mr.]] and [[Test]].

Here comes the approach it is a Widget and a macro in combination:

Widget

/*\
title: $:/core/modules/macros/roles.js
type: application/javascript
module-type: macro
Making some replacements in Textinputs
\*/

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

/*
Information about this macro
*/
  exports.name
 = 'roles';
  exports.params = [{ name: 'text'  }];
/*
Run the macro
*/
exports.run = function(text) {
var regex = /\[.*?\]\]/g;
var found = text.match(regex);
var remove = found.join();
var result = remove.replace(/,/g, ' ');
return result
} ;

Macro

\define preroll()



<$macrocall $name="roles" text={{!!dialogue}}/>

\end
\define rollen()
<$wikify name=rollo text=<<preroll>> output="text">
<$list filter=<<rollo>> >
{{!!title}} <br>
</$list>
</$wikify>
\end

How can I handle that?

Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Mark S.

unread,
Jul 15, 2019, 4:48:36 PM7/15/19
to TiddlyWiki
Actually, what I think you see is

Mr.
Test

What's happening is that the macro is being returned as [[Mr. Test]] and then stripped of the brackets at the WikifyWidget. One work-around is to
add additional brackets back in your macro.

Also, this

var regex = /\[.*?\]\]/g;

Should be this

var regex = /\[\[.*?\]\]/g;

So then we end up with:

/*\
title: $:/core/modules/macros/roles.js
type: application/javascript
module-type: macro
Making some replacements in Textinputs
\*/


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

/*
Information about this macro
*/

  exports
.name
 
= 'roles';
  exports
.params = [{ name: 'text'  }];
/*
Run the macro
*/

exports
.run = function(text) {
var regex = /\[\[.*?\]\]/g;
var found = text.match(regex);
var remove = "[[" + found.join("]] [[") + "]]";
//var result = remove.replace(/,/g, ' ');
var result = remove ;
return result
} ;

})();

Now you get the links listed one after another. However, they're not listed AS links because they're viewed as text strings. You
can probably use <$link> widget to turn them back into links, if that's what you want.

Good luck





Jan

unread,
Jul 15, 2019, 6:41:53 PM7/15/19
to tiddl...@googlegroups.com
Hi Mark,
great, this works perfect and I do not need links anyway.
Thanks for solving this!

Best wishes Jan
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Mat

unread,
Jul 16, 2019, 7:27:50 AM7/16/19
to TiddlyWiki
Mark, I have a strong feeling your macro will be very useful for me.
Would you mind documenting it a little in the "Information about this macro" part (what it does, how to use)?
And might it be something relevant to integrate into your PR?
Thank you!

<:-)

Mark S.

unread,
Jul 16, 2019, 10:38:40 AM7/16/19
to TiddlyWiki
Do you mean Jan's macro?

Jan

unread,
Jul 16, 2019, 3:14:15 PM7/16/19
to tiddl...@googlegroups.com
Hi Mark, Hi Mat
I am happy to hear that.
To be honest I would not have not have managed to do this without your help, in fact it is the second thing in javascript I ever did.
I got a small amelioration:
if (text !== null) {...
avoids red alerts which were happend before so we have this:

/*\
title: $:/core/modules/macros/roles.js
type: application/javascript
module-type: macro
Making some replacements in Textinputs
\*/

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

/*
Information about this macro
*/
  exports.name

 = 'roles';
  exports.params = [{ name: 'text'  }];
/*
Run the macro
*/
exports.run = function(text) {
if (text == null) {      

    var text = " ";  

}  
var regex = /\[\[.*?\]\]/g; 
var text = text.match(regex);
if (text !== null) {      
var text = "[[" + text.join("]] [[") + "]]";
return text
}
} ;

})();
It would be nice to turn this into a general extract macro with start and end parameters and the option to keep or chop start and end. So far Thomas Elmingers extract Macro did this Job for me but some things like those brackets are stubborn. I will see what I can achieve.
Cheers! Jan
--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Mat

unread,
Jul 21, 2019, 3:57:59 PM7/21/19
to TiddlyWiki
Jan wrote:
I will see what I can achieve.

Jan, are you making any progress with this? I'm really curious to see what you achieve. As you may know, I once created the cherrypicker macro which was later a basis for T.Elmigers exctract macro, and I've always felt there should be a proper js solution to this (mine is only wikitext).

<:-)

 

Jan

unread,
Jul 21, 2019, 4:30:49 PM7/21/19
to tiddl...@googlegroups.com
Hi Mark,
you are right, I will try to finish this right now. I was preoccupied with the importing of text-files as you can see in Szenio.de/Test the last days

Jan.
--
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.

Jan

unread,
Jul 21, 2019, 6:03:37 PM7/21/19
to tiddl...@googlegroups.com
Hej Mat,
I am a little stuck, I ve been looking for the site for the site Widgets for beginners but it seems to be down. (https://groups.google.com/forum/#!topic/TiddlyWiki/qgNY0iKRrOU) but it seems to be gone.
The extract.js widget should have the following params:

filter: A filter defining on which tiddlers the widget shall be applied,
start: A start string
end: An end string (which is the same as the start-string if nothing is defined
skip: A value determening whether start-string and end-string shall be chopped from the result. Default:yes/remove

Sorry, at the moment it appears that I can't even enter the params properly. Defining the filter and getting seems to be the hardest task.

Jan

Mark S.

unread,
Jul 21, 2019, 9:52:36 PM7/21/19
to TiddlyWiki
What you have so far is a JS macro, not a widget. Widgets are, IMO, much more complicated than macros (and filter operators) and assume some
deep understanding of TW without any clue how to gain that understanding.

You can find a write-up on JS macros here:


Good luck!

On Sunday, July 21, 2019 at 3:03:37 PM UTC-7, Jan wrote:
Hej Mat,
I am a little stuck, I ve been looking for the site for the site Widgets for beginners but it seems to be down. (https://groups.google.com/forum/#!topic/TiddlyWiki/qgNY0iKRrOU) but it seems to be gone.
The extract.js widget should have the following params:

filter: A filter defining on which tiddlers the widget shall be applied,
start: A start string
end: An end string (which is the same as the start-string if nothing is defined
skip: A value determening whether start-string and end-string shall be chopped from the result. Default:yes/remove

Sorry, at the moment it appears that I can't even enter the params properly. Defining the filter and getting seems to be the hardest task.

Jan





Am 21.07.2019 um 22:30 schrieb Jan:
Hi Mark,
you are right, I will try to finish this right now. I was preoccupied with the importing of text-files as you can see in Szenio.de/Test the last days

Jan.

Am 21.07.2019 um 21:57 schrieb Mat:
Jan wrote:
I will see what I can achieve.

Jan, are you making any progress with this? I'm really curious to see what you achieve. As you may know, I once created the cherrypicker macro which was later a basis for T.Elmigers exctract macro, and I've always felt there should be a proper js solution to this (mine is only wikitext).

<:-)

 
--
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 tiddl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages