[Auto] Capitalize the First Word Following a Markdown Character (`#`, `*`, `>`)

Not sure if this is a bug/feature (:sweat_smile:) but here it goes anyways:

When creating a new draft using Markdown syntax, I’ll often start with a level-one heading (#)

I type this

# title

expecting, but not receiving this

# Title

I noticed that even though I have the Capitalize setting on in Drafts set to Sentences, Drafts does not auto-capitalize the “T” in the first word (in the aforementioned example, “title”).

Of course, if I omit the Markdown character #, “title” autocorrects to “Title.”

?

1 Like

I forgot that I already asked this question. Anyone have an idea?

The first word in your sentence is a symbol, so my expectation is the capitalisation would be applied to that and not the second word. :man_shrugging:t2:

Right. So what I’m wanting is for that default iOS capitalization to be applied to the first actual word (not the Markdown symbol) :wink:

There has to be a way to tweak the Markdown symbol insertion script itself so that this is the case. (Obviously, there’s some special juice applied to the Markdown insertion, because it is smart enough to allow for a space to be inserted after invoking the symbol insertion.)

Here’s the script that adds the Markdown heading symbol:

// Apply Markdown Header to current line

var lnRange = editor.getSelectedLineRange();
var ln = editor.getTextInRange(lnRange[0],lnRange[1]);
var selRange = editor.getSelectedRange();

var prefix = "#";
if (ln.length == 0 || (ln && ln[0] != " " && ln[0] != "#")) {
  prefix = "# ";
}

editor.setTextInRange(lnRange[0],lnRange[1],prefix+ln);
editor.setSelectedRange(selRange[0]+prefix.length,selRange[1]);

(I’m surprised no one else finds it frustrating to have to manually capitalize that first word after the Markdown insertion :sweat_smile:)

Right, so you always use an action to set the Markdown. That’s going to be independent of that setting you referenced.

Personally I tend to just type most Markdown manually and I type capital letters when I need them. I don’t know if I’m typical in that regard, but I don’t find the need to use an action to apply the heading syntax.

You can definitely use JavaScript to captitalise a word (ref. https://dzone.com/articles/how-to-capitalize-the-first-letter-of-a-string-in), but you may also want to consider title casing vs. sentence casing. You could integrate either of these with your script above.

If you’re using Drafts on iPad (with a keyboard), auto-capitalization applying to the first word after a Markdown symbol insertion isn’t as important. But on the iPhone, couldn’t we expect that the typical iPhone OS 1 auto-capitalization would apply to the first word?

It’s even more egregious when considering the Markdown symbol for an ordered or unordered (or task list, in Drafts).

Like, after starting the list items, when returning to a new line and new list item, shouldn’t the next list item capitalize the first word?

* List item 1
* list item 2, which is a new line, which should ostensibly begin with "List item 2,"  but "l" in "list" is not capitalized, therefore everything sucks

Again, personally, I would say that this comes back to the asterisk symbol being the first word, not the word that follows it. So to my current way of thinking, I’d say no, the next list item shouldn’t auto capitalise; based on the settings and my expectations of the behaviour those settings produce.

I would say that this comes back to the asterisk symbol being the first word, not the word that follows it. So to my current way of thinking, I’d say no, the next list item shouldn’t auto capitalise; based on the settings and my expectations of the behaviour those settings produce

I’m not arguing that the results I’m having differ from what we would expect given the implementation. It is what it is!

What I’m arguing for is a more intelligent implementation, which takes into consideration that although the Markdown symbol is literally the first character on the line, maybe the iOS-style auto-capitalization should be applied to the first letter of the first word after the symbol :wink: