Searching for words

I spotted this earlier today, but have been travelling or busy with other things most of the day, so I didn’t get chance to look at it in more detail until this evening, and spent a few hours putting something together.

Other than the phone and Drafts aspect, it was this that got me thinking. It sounded like this was purely a find operation (rather than edit), and the “highlighting” aspect also piqued my interest as the Drafts editor doesn’t really align itself to that sort of thing unless you start modifying the text and applying syntax highlighting - which sounded like it would be going in the wrong direction.

Instead I started to think about processing the text and doing highlighting of search criteria in the ways many web sites do. Fortunately, there are libraries out there that do exactly that sort of thing, so all it should take is a bit of a wrapper for Drafts to take advantage of that. And so that’s what I tried to do.

It comes down to one action, but I’ve built a small action group around it to illustrate how to use it as it has a fair bit of flexibility to it.

In the action group, you’ll find a set of documentation/instructions, which are reproduced in the action directory.

You’ll find a couple of actions that generate sample drafts to show off the examples, as well as a set of examples.

There is a clonable action which you can duplicate and tweak the settings of to build your own standard searches.

Finally, there is a helper action that does the integration work with a library called mark.js.

In the examples you will find ones that use predefined text strings and regular expressions as well as ones that display a prompt and allow you to enter a search string or regular expression. In the examples, you will also find one that will search for text strings that are maintained in a draft (each line defines one string), and one of the sample drafts will generate a sample draft for you to work with the sample text the other action in the same section generates.

Hopefully, this covers the sorts of cases you were envisaging and allows you to quickly and easily build out your own highlight actions for your relatives. With any luck, others will find it useful too.