Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ꜱᴍᴀʟʟ ᴄᴀᴘꜱ Action #120

Open
extratone opened this issue Nov 3, 2024 · 0 comments
Open

ꜱᴍᴀʟʟ ᴄᴀᴘꜱ Action #120

extratone opened this issue Nov 3, 2024 · 0 comments
Assignees
Labels
configuration documentation Improvements or additions to documentation

Comments

@extratone
Copy link
Owner

extratone commented Nov 3, 2024

Updated 11032024-012821


Social

<iframe src="https://mastodon.social/@DavidBlue/113417837332892729/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://static-cdn.mastodon.social/embed.js" async="async"></script>

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
  • You want an action for the Drafts application.
  • The action should convert any selected text to small caps.
  • If no text is selected, it should presumably do nothing.
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
  • This action will only work on the selected text. If you want to convert the entire draft to small caps, you'll need to modify the code to get the entire draft content instead of just the selection.
  • You can customize the action further by adding options to control the case of the converted text, such as uppercase or title case.
  • Remember to test the action thoroughly to make sure it works as expected.

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)
@extratone extratone added configuration documentation Improvements or additions to documentation labels Nov 3, 2024
@extratone extratone self-assigned this Nov 3, 2024
extratone added a commit that referenced this issue Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant