Each script works pretty much as you’d expect. Type in some normal text, select the portion you want converted, and tap the appropriate button. Voila!
The script that does the encircling is this:
The structure of the
replace method can take a function as the replacement argument. That function,
lookup, is defined in Line 7 and the
trans object it uses to replace characters is built in Lines 9–11. The regular expression that serves as the first argument to
replace is built in Line 5 from the string of all convertible plain characters. Line 16 gets the selected text from the draft, converts it, and replaces the selection with the converted text.
The key that applies this script is built by tapping the pencil icon at the end of Drafts’ custom key strip, tapping the + button to add a new key, choosing the Script option, and then entering the label, name, and script. When you’re done, a new key with that label will appear in the strip.1
The flipping script is built the same way.
Apart from the two strings that define the conversion, there are a few other differences between this script and the encircler:
- The regular expression in Line 5 had to be handled more carefully. The closing bracket character had to be escaped (double escaped, actually) so it would close off the character class prematurely.
- Because there aren’t good upside-down versions of all the capital letters, everything is converted to lowercase first. That’s done in Line 7.
- To look decent in the flipped condition, the order of the letters has to be reversed. That’s done by creating an array of characters in Line 13, reversing it in Line 14, and then joining them back together in Line 15.
Finally, there’s the strikethrough script.
This one doesn’t do any replacing, because there aren’t “stuck out” versions of all the letters. Instead, it puts the COMBINING LONG SOLIDUS OVERLAY character (decimal 824, hex 0338) after every character in the string. The combination appears as a character with a diagonal line through it.
It should be easy enough to use these scripts as guidelines for creating other conversions. sᴍᴀʟʟ ᴄᴀᴘs, for example, seems like something Than Tibbetts should be all over.
Because these key definitions seem fairly simple and robust, I’ve uploaded them to the Keyboard Extensions section of the Drafts Actions Directory. You can install them from there if you don’t want to go through the character-building2 exercise of making them yourself.
Yes, one screenshot shows the label as Ⓐ, and the other shows it as ⓐ. I changed the name between screenshots and didn’t feel like going back and redoing the earlier one. ↩
I have no shame. ↩