Trick to assign actions to Bold/Italic/Underline commands

This is a bit of goofiness that is the result of the way iOS handles bold, italics and underline commands and input views.

Bold, italics and underline commands have their own routing, regardless of whether they are triggered by using external keyboard shortcuts (⌘-B, ⌘-I and ⌘-U), triggered from the text selection menu, or from the iPad keyboard shortcuts. Since Drafts intervenes in this process to be able to react to those external keyboard shortcuts, if you trigger bold, italic or underline via any of the other methods, you will get the same thing happen as if you hit the external keyboard shortcut.

The default installation of Drafts comes with Markdown bold and italics actions assigned to the ⌘-B and ⌘-I shortcuts…so they are also triggered if you select “Bold” or “Italic” from the text selection menu. You can change these assignments if there are other actions you would rather run using those buttons…or assign some other action to the ⌘-U shortcut, and you would be able to run that action by tapping the “Underline” commands in the other locations.

Not, perhaps, that exciting, but a handy little tip if you want to have another tool accessible from the text selection menu - like say assigning ⌘-U to an action which toggled title-lower-upper case on the selection.

3 Likes

I still cannot seem to get underline to work in a draft. Italic and bold work fine, but underline doesn’t seem to make any change

1 Like

There is no such thing as underline in Markdown, so the underline command has nothing attached to it. If you want to attach a function to it, you can by assigning the ⌘-U keyboard shortcut to an action.

2 Likes

Markdown does not support underlining but does support bold and italic; Markdown being most users’ default draft syntax. This is probably why Greg separated that CMD+U out from Bold and Italic in his original posting and why it wouldn’t do anything by default.

Is there a workaround that works on an iPhone ?

There is no such thing as underline in Markdown, so the underline command has nothing attached to it. If you want to attach a function to it, you can by assigning the ⌘-U keyboard shortcut to an action.

This trick works on iPhone. Even if you do not have an external keyboard connected, if an action is assigned to these shortcuts, the bold/ital/underline buttons in the text selection menu will fire that action.

You could use ⌘U to insert <u>words here</u> around the selected word. It’s HTML and not Markdown, but it will work in previews just fine.

But I don’t have a command key on my iPhone, so how do I set that shortcut ?. While I use drafts all day long, and have many built actions that save me endless amounts of time, I do not anything about the coding in the background

I think you two are talking past each other.

Jeremy -

You seem to want to make some text in Drafts underlined. Right?

That just isn’t currently possible. Drafts are plain text, not rich text. And there’s no plain text way (at least in Markdown) to specify underlining. The bold and italic formatting are part of markdown and the fact that Drafts does a bit of WYSIWYG with them is just a convenience. (Note that Drafts adds the plain text asterisks and underscores, not just the formatting in the abstract.)

Given that underlining doesn’t work, Greg’s tip above is a hidden way to access an action using the “Underline” command. It could trigger whatever action you might want. To specify an action to be triggered in this way, you need to modify the action so that its assigned keyboard shortcut is command-u. You do that by editing the action, which can be done on a phone or an ipad.

To trigger such an action on an iPhone, you’d use the normal “underline” button that appears when you select some text (it’s that black pop-up, then the BIU button, then “underline”).

That’s not terribly handy on the iphone, but you can do it.

1 Like

Thanks. I did try that and the command etc is all there, but it doesn’t seem to actually underline it. This is certainly not important, it would just be helpful

J

1 Like

Yep. It wont actually underline it in Drafts because Drafts doesn’t display underlining.

If you are trying to underlining in text that you send to other apps, then Tim’s tip above is probably the best way to do that.

1 Like

I cannot for the life of me bold or italic or underline in the iPhone app. Okay, in that slow way, I can highlight on the phone and scroll through to the BIU options. But keyboard shortcuts do not work in the desktop app, and even from the phone - so it puts it in markdown language, but if I export that to a text file it’s just in markdown, it’s not bold or italics.

In other people’s screenshots, they have the option. I don’t. What am I doing wrong?
On Drafts5. Have paid account.

Thanks.

Text files are plain text. No formatting. Try converting your text file to something that can be displayed with rich formatting; e.g. export as something other than a text file.

HTML is often a good option. Whilst it is stored as plain text, any browser can render it as rich text.

I’m wondering if @melaniels knows how to export to e.g. HTML (or RTF). The latter I don’t know myself, so no insult intended.

By the way, I don’t think there is an underline in Markdown. In which case (ab)using the HTML <ins> tag might be the way to go.

I have no need to export to HTML, and that wasn’t my question.

I would like to use bold or italic text in drafts, and I don’t see how.

I would like to do this from the new Drafts desktop app, and from my phone. The normal keyboard shortcuts (command-B; command-i) do not work.

Thanks.

Drafts is a plain text app. It does not do bold/italics or other rich text natively.

If you are trying to convert to rich text from Markdown, that can only be done on iOS at this time. That is done via actions in Drafts, and actions are not available in the Mac version yet.

I don’t seem to be able to escape Markdown in my iOS app. My “current draft” setting is set to Plain Text and the Default is set to plain text, but as soon as I try to edit some text (make it bold etc” it applies the markdown example to the text. I did not used to do this

That may well be by design as you can’t bold plain text. Maybe by selecting to bold it’s being helpful by switching to a format that supports bold tagging and some visual display of that - Markdown.

That little tip at the end of your post is very interesting and would be quite useful for me. How do you set this “toggle between title-lower-upper” up? I haven’t been able to get my head around it. Thanks very much for a practical help how to do it.

There’s an action in the action directory that does Mixed case -> Upper -> Lower -> Initial Caps - Case Toggle Action.

But note that Initial Caps is not quite the same as title case.

For a starting point for broader text case and style changes, maybe take a look at Tim’s Text Modifier action in the action directory. This deals with various text cases, but with a prompt button based selection rather than a cyclic one.

In terms of figuring out a cycle of toggling, upper and lower is easy. Just check if the text is upper or lower case.

Perhaps something along these lines…
if(editor.getSelectedText().toUpperCase() == editor.getSelectedText()) alert("Text is uppercase");

True title case is actually much more problematic as you may be able to tell from comparing the Initial Caps vs. Title Case. If you were happy with Initial Caps, then you just check the case of the first and second alphabetic characters of the selection; but the first action gives you a ready made solution in any case.

The second action accounts for the non initial capping for short words, so you could search for longer words … but the title may not have any. A better solution would be to strip out the potentially always lower cased words and then compare against what’s left.

But… there are some things that should always be capitalised - e.g. “IBM”, “DHL”. These pose an issue for titling, and even when lower casing, some people always prefer/believe/desire that proper nouns remain capitalised.

Ultimately you can get a pretty good automation set-up from these two, but if you have some exceptions, you may need to incorporate these yourself, or handle them manually.

Hope that helps.

1 Like