This is a private note that has been shared.


ꜱᴍᴀʟʟ ᴄᴀᴘꜱ Action

Updated 11032024-010753


Social

Thanks to Google Gemini, I created an Action for @drafts that converts currently-selected text to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ. https://directory.getdrafts.com/a/2VW

Meta

Description

Convert the current text selection to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case.

Directory Description

Convert the current text selection to ꜱᴍᴀʟʟ ᴄᴀᴘꜱ case.


Babylon

Prompt:

I’d like to create an Action for Drafts (getdrafts.com) which transforms the currently selected text (selection_only) into small caps.

Initial Response

Absolutely! I can help you create a Drafts action that transforms selected text into small caps. Here’s how we can approach this:

Understanding the request
Overview of the solution

We’ll use the Drafts scripting API to:

  1. Get the currently selected text.
  2. If there is no selection, exit.
  3. Convert the selected text to small caps.
  4. Replace the selection in the editor with the converted text.
The code
// Get the currently selected text.
let selection = editor.getSelectedText();

// If there is no selection, exit.
if (!selection) {
  context.cancel();
}

// Convert the selection to small caps.
let smallCapsText = selection.toLowerCase();

// Replace the selection with the small caps text.
editor.setSelectedText(smallCapsText);
Implementation instructions
  1. Open the Drafts application on your device.
  2. Create a new action.
  3. In the action editor, select “Javascript” as the action step type.
  4. Copy and paste the code above into the code editor.
  5. Save the action with a descriptive name, like “Small Caps”.
  6. Select some text in a draft and run the action. The selected text should now be in small caps.
Additional notes

I hope this helps! Let me know if you have any other questions or need further assistance.

Correction Prompt:

No, small caps like this: sᴍᴀʟʟ ᴄᴀᴘs

Corrected Response

Ah, I understand! You’d like to use the Unicode small caps characters like sᴍᴀʟʟ ᴄᴀᴘs.

Here’s the updated code:

// Get the currently selected text.  
let selection = editor.getSelectedText();  
  
// If there is no selection, exit.  
if (!selection) {  
context.cancel();  
}  
  
// Convert the selection to small caps.  
let smallCapsText = selection.toLowerCase().replace(/[a-z]/g, function(char) {  
switch (char) {  
case 'a': return 'ᴀ';  
case 'b': return 'ʙ';  
case 'c': return 'ᴄ';  
case 'd': return 'ᴅ';  
case 'e': return 'ᴇ';  
case 'f': return 'ꜰ';  
case 'g': return 'ɢ';  
case 'h': return 'ʜ';  
case 'i': return 'ɪ';  
case 'j': return 'ᴊ';  
case 'k': return 'ᴋ';  
case 'l': return 'ʟ';  
case 'm': return 'ᴍ';  
case 'n': return 'ɴ';  
case 'o': return 'ᴏ';  
case 'p': return 'ᴘ';  
case 'q': return 'ǫ';  
case 'r': return 'ʀ';  
case 's': return 'ꜱ';  
case 't': return 'ᴛ';  
case 'u': return 'ᴜ';  
case 'v': return 'ᴠ';  
case 'w': return 'ᴡ';  
case 'x': return 'x';  
case 'y': return 'ʏ';  
case 'z': return 'ᴢ';  
default: return char;  
}  
});  
  
// Replace the selection with the small caps text.  
editor.setSelectedText(smallCapsText);

This script now iterates through each character in the selected text and replaces it with its corresponding Unicode small caps equivalent.

The implementation instructions remain the same. Just replace the previous code with this updated version in your Drafts action.

Sources
  1. https://github.com/dtmorrow/MyLibs](https://github.com/dtmorrow/MyLibs) subject to license (Unlicense)
  2. https://github.com/devho813/ros-ranking](https://github.com/devho813/ros-ranking)