[TW5] Regex String Replacments — Possible? Terrible Idea?

140 views
Skip to first unread message

Scott Simmons

unread,
Dec 31, 2015, 10:12:38 AM12/31/15
to TiddlyWiki
Having just mentioned AutoCorrectPlugin, here's a stranger, wish-listier request/fantasy:

Could you write a TW5 Javascript plugin that would perform the same sort of string transformation — but using complex regular expressions?  :-O

I regularly get task lists from my co-workers that I transform into checklists.  Currently, I do this by copying the list to Notepad++, running a saved macro, and copying the output to my TiddlyWiki.  For example, I might get a list like this:

Update Tom on Open Tickets
Where do we stand with Friday's ads?
Send Ed new reports.
Proofread "Title of a Story"

... which I transform into wikitext like this:

#<div class="todo"><$checkbox field="todo_updatetomonopentickets" checked="done" unchecked="not done" default="not done">Update Tom on Open Tickets</$checkbox></div>
#<div class="todo"><$checkbox field="todo_wheredowestandonfridaysads" checked="done" unchecked="not done" default="not done">Where do we stand with Friday's ads?</$checkbox></div>
#<div class="todo"><$checkbox field="todo_sendednewreports" checked="done" unchecked="not done" default="not done">Send Ed new reports.</$checkbox></div>
#<div class="todo"><$checkbox field="todo_proofreadtitleofastory" checked="done" unchecked="not done" default="not done">Proofread "Title of a Story"</$checkbox></div>

How cool would it be if I could simply paste the list into TW and have it automagically transformed into ready-to-work-on checklist items?

What I would really want (I think) is a macro that isn't global to all tiddlers, that I could call on in specific tiddlers — and that I could pass my complex regular expression to as a parameter.  (That would allow me to keep regexes in their own tiddlers and transclude them as the parameter of the macro.)  This would enable me to create a new tiddler and save it with something like this at the beginning:

{{myCrazyMacro}} <<callToMyCrazyMacro {{myWackyRegExParamInSomeTiddler}}>>

Then drop my ready-to-be-transformed text strings into it and have them transformed into TW-friendly task lists (or whatever I might regex 'em into in future tiddlers).

Tobias Beer

unread,
Jan 1, 2016, 5:50:24 AM1/1/16
to tiddl...@googlegroups.com
Hi Scott,
 
Could you write a TW5 Javascript plugin that would perform the same sort of string transformation — but using complex regular expressions?  :-O

Sure doable. The question for me would be: Can it be so generic as to not be tied to a single process / workflow? ...e.g. "make my type of checklists".
 
I regularly get task lists from my co-workers that I transform into checklists.  Currently, I do this by copying the list to Notepad++, running a saved macro, and copying the output to my TiddlyWiki.  For example, I might get a list like this:

Can you perhaps post the the regex and the macro for your above example so we get a true feel for the complexity involved and perhaps more specifically consider whether or not or how TiddlyWiki could be leveraged to try and achieve generic input => output transformations in the first place?

Sounds like you want to deserialize some input text format into an array of items holding variables filled by regex pattern matching ...and then serialize that with TiddlyWiki components / templates... that come with appropriate placeholders... and eventually save the lot to some place.

I could imagine some "insert" button in the editor (or a keyboard shortcut) that...
  1. opens a modal dialog where I can chose from a (filterable) list of predefined transformation patterns / templates already defined
  2. have an input field to insert my input text
  3. click a button that generates the output text based on the transformation rules / framework
  4. that I get to also edit and adjust right there
  5. and finally click "ok" to insert the end result at the caret position in the editor
Best wishes,

Tobias.

Julio Cantarero

unread,
Jan 2, 2016, 4:53:46 PM1/2/16
to TiddlyWiki
Hi,

Just in case this helps, there is a simple plugin to do Regex replacements in a tiddler, published by danielo at http://danielorodriguez.com/TW5-searchNreplace/

It may not be enough to do what Scott is requesting, because I think you cannot currently control the multiline option of Regex.
More information about this plugin in the group here: https://groups.google.com/forum/#!searchin/tiddlywiki/exporter|sort:date/tiddlywiki/WE7mYrz_QbA/mtuTDwP9Bd0J

Regards,
Julio

Secret-HQ

unread,
Jan 4, 2016, 12:14:38 PM1/4/16
to TiddlyWiki
Thanks, Julio!

@Tobias:  I'm not ignoring your request, but one of my first-of-the-year tasks is to tidy up my N++ macros, and when I get that knocked out, I'll try to post a couple of different examples of the type of thing I might use such a plugin for.  :)

Reply all
Reply to author
Forward
0 new messages