RegEx for tiddlers?

125 views
Skip to first unread message

RunningUtes

unread,
Feb 2, 2018, 7:27:38 PM2/2/18
to TiddlyWiki
I was thinking that it would be great to have a search and replace function that could be used in tiddlers. I couldn’t find anything already coded, but did find a bookmarlet that looks promising. I would like to have this work only in the opened text area of the tiddler being editied.

How could this bookmarket be modified?

Bookmarklet below:

<pre>
javascript:var count=0;
function htmlreplace(a,b,element){
if(!element)element=document.body;
var nodes=element.childNodes;
for(var n=0;n<nodes.length;n++){
if(nodes[n].type&&nodes[n].type.toLowerCase()=='textarea'){
var r=new RegExp(a,'gim');
if(nodes[n].value.match(r)){
count++;
}
nodes[n].value=nodes[n].value.replace(r,b)
}
else if(nodes[n].nodeValue && nodes[n].nodeValue.length > 0){
var r=new RegExp(a,'gim');
if(nodes[n].nodeValue.match(r)){
count++;
}
nodes[n].nodeValue=nodes[n].nodeValue.replace(r,b)
}
else{
htmlreplace(a,b,nodes[n])
}
}
}
htmlreplace(prompt('find'),prompt('replace'));
alert('replaced '+count+' words.');
</pre>

Birthe C

unread,
Feb 2, 2018, 7:57:47 PM2/2/18
to TiddlyWiki
Must it be a bookmarklet? I am not good with regEx, so I have not used it, but you should be able to use it https://danielorodriguez.com/TW5-searchNreplace/ 


Birthe

TonyM

unread,
Feb 2, 2018, 8:26:17 PM2/2/18
to TiddlyWiki
I used to use itsalltext the FireFox Plugin to open any browser text area in NotePad++  It is not longer working on current firefox versions.

I then used NotePad++ advanced search and replace features.

FireFox suggests a replacement withExEditor that looks like it will do the job however it uses a messaging system on the host (your computer) installed on nodeJS, so the setup is not as simple as I would hope however it may provide additional features at least developers may want to use, and may offer some ways to integrate with the desktop.

Here is the blurb from the plugin, which I will install and report on sooner or later.

From the context menu (right click), you can "View source" "View selection" or "Edit text" with your favorite editor."View source" "View selection" or "Edit text" with your favorite editor.
Enabled in (X)HTML, JavaScript, CSS, MathML, SVG, XML, etc.

Requirements:
To use withExEditor, you also need to prepare a host which executes your editor.
The browser interacts with the host via messages, and the editor is executed by the host.

Context Menus:
* View Page Source with exEditor
Creates a copy of the page, save as a temporary file, and opens it with an external editor.
If you are browsing a local file, then the local file will be opened directly.

* View MathML Source with exEditor
Enabled on MathML elements, and shows a generated DOM tree.

* View SVG Source with exEditor
Enabled on SVG elements, and shows a generated DOM tree.

* View Selection with exEditor
Shows a generated DOM tree of selection in XML format.
If there are multiple ranges in selection, each range will be shown with a comment as a delimiter.
If the selection is not DOM parsable (like JavaScript, CSS), a file that contains only the range of text selected will be created.

* Edit Text with exEditor
Enabled on input elements, textarea element and editable elements.
Edited contents will be synchronized when you go back to the browser and move focus to the element which you've edited.

Options:
The following items can be set.
* Choose toolbar button icon.
* Configure access key.
* Choose whether to enable during private browsing.
* Choose whether to enable only when content is editable.
* Choose whether to enable automatically synchronize edited content on specific sites.

Regards
Tony

BurningTreeC

unread,
Feb 2, 2018, 10:10:52 PM2/2/18
to TiddlyWiki
Hi @RunningUtes,

you could use CodeMirror's search&replace: http://codemirror.net/doc/manual.html#addon_search

I've used it before, it works :)

Simon

Thomas Elmiger

unread,
Feb 3, 2018, 5:43:42 AM2/3/18
to TiddlyWiki
Hi Simon,

Do you use this with the official Code Mirror plugin?
https://tiddlywiki.com/plugins/tiddlywiki/codemirror/

How did you include the addon?

Best regards,
Thomas

BurningTreeC

unread,
Feb 3, 2018, 6:40:18 AM2/3/18
to TiddlyWiki
Hi Thomas,

yes with the official one

I have to look for the wiki where I did it, I'll post you the how-to then

Simon

BurningTreeC

unread,
Feb 3, 2018, 7:39:10 AM2/3/18
to TiddlyWiki
Ok @Thomas, @RunningUtes, @all,

see at http://muritest.tiddlyspot.com, there you see a working search and replace and a how-to

have fun with it!

all the best,
Simon

BurningTreeC

unread,
Feb 3, 2018, 7:47:43 AM2/3/18
to TiddlyWiki
you may have to set a fixed height for the editor to jump to lines by search

@TiddlyTweeter

unread,
Feb 3, 2018, 9:06:10 AM2/3/18
to TiddlyWiki
Ciao RunningUtes,

IF what you want to do regex Tiddler Danielo's tool is pretty good, as Birthe mentioned. https://danielorodriguez.com/TW5-searchNreplace/

Stephen's also http://skplugins.tiddlyspot.com/#FindReplace, though not full regex. Its well integrated into the editor.

IF what you want to do regex that is consistent  and automatic so that its always run on a specific type of content, look to BJ's Flexibility plugin that defines a Content Type that will always have regex you define applied before the main parser kicks in. Its the best IF the input text has a standard pattern of transform you need as its automatic once set-up. http://flexibility.tiddlyspot.com/

Best wishes
Josiah

Thomas Elmiger

unread,
Feb 3, 2018, 10:13:53 AM2/3/18
to TiddlyWiki
Thank you, Simon!

Installation went well, I also copied your "Codemirror keyboard controls" cheat sheet. The codemirror plugin added about 900 kilos to my wiki, but it seems to be worth a try.

Cheers,
Thomas

BurningTreeC

unread,
Feb 3, 2018, 11:50:28 AM2/3/18
to TiddlyWiki


Am Samstag, 3. Februar 2018 16:13:53 UTC+1 schrieb Thomas Elmiger:
Thank you, Simon!

Installation went well, I also copied your "Codemirror keyboard controls" cheat sheet. The codemirror plugin added about 900 kilos to my wiki, but it seems to be worth a try.

Very good, yes it's a bit heavier, almost a ton 

@TiddlyTweeter

unread,
Feb 3, 2018, 1:07:48 PM2/3/18
to TiddlyWiki
Ciao TonyM

I'm still on Firefox ESR precisely because it lets you do this for a few months yet.

ItsAllText is a great way to get more out of TiddlyWiki without some TW developer having to bend backwards to get back to what we had.

I use IAT with the sophisticated text editor TextPad and with PowerGrep on Windows. Uncomplicated paths to a bigger world made made much, much smaller by the obsession with narrowing Firefox to "protect us" from a threat that never was.

Apart from moaning I'd just say we need get smarter to reclaim the ground lost.

Best wishes
Josiah
Reply all
Reply to author
Forward
0 new messages