Auto Pair Markdown

Obsidian has a simple option that has spoiled me. For Italics, Bold, Highlights and Links it has an option to auto pair the syntax. So when I hit CMD+I I get ** and my cursor is sitting in the middle ready to type. Is this possible in Drafts?

I checked preferences and searched the forum, I can’t find a mention.

Almost all text manipulations are implemented in actions in your actions list, and all are modifiable. They also have keyboard shortcuts attached for those key commands.

Most of the common Markdown ones (bold/italic/etc.) ship by default in the “Markdown” action group.

The behavior that ships for the bold - emphasis actions is to wrap the text with the pair _if there is a text selection or insert only the markup if there is not, but could be modified by tweaking the scripts just a little. This would modify the “Markdown Bold” action to behave like you describe:

// Apply Markdown bold to selection, or insert ** if no selection
const markup = "**";

const sel = editor.getSelectedText();
const [st, len] = editor.getSelectedRange();

if (!sel || sel.length == 0) {
  editor.setSelectedText(markup + markup);
  editor.setSelectedRange(st + markup.length,0);
else {
  editor.setSelectedText(markup + sel + markup);
  editor.setSelectedRange(st + len + (markup.length*2),0);

The only change in this from the script in the default version is the added + markup just after the if statement to insert the ** twice.


Thanks I’m trying now. Cool to see how actions are built. I had never looked under the hood.