Format selected text in code like slack

Hello,

I am currently on MacOs and I would like to format selected text in code format while pressing only backtick like Slack does.

I cannot set an hotkey with only the backtick key.

Is it possible?

Thank you.

That already works by default. Make sure Settings > Editor > “Auto pair Markdown syntax” is enabled. If you’re doing a code block instead of inline code you’ll need to type 3 backticks.

This works for bold and italic formatting. Not for code formatting.
Screenshot 2024-02-01 at 10.48.06

That text should probably be changed. Or maybe I’ve misunderstood which setting controls this, but I can definitely highlight text and type backticks to make it a code block.

When I do that, it deletes the highlighted text and inserts a backtick caracters.
Do you have any clue why this does not work ?

@CawlinTeffid (after toggling the Auto pair Markdown syntax back on) I found that the following quote characters work on MacOs: " and ', but not `. The backtick replaces the selected text.

After a little more testing I found the following to work: [{($%='", but not <«’”`´#. So there might be a need/want to update which characters are to be allowed when doing the auto pairs. I would consider the backticks, various smart quotes, and the angular quotes to be especially useful. Quite a few languages uses something besides the normal straight single and double quotes.

3 Likes

Here is a video of backticks working as expected in the Sandbox vault on a Mac:

It also works for inline code.

I don’t know why it’s not working is some vaults, but the troubleshooting steps in the Obsidian debugging guide can help find the source of the problem: About the Bug reports category - #11 by system

Trying the same thing in the Sandbox Vault (does not work):

Strange! Can you run “Show debug info” in the command palette (in the Sandbox vault) and paste the output here?

Also it would help to mention your MacOS version — mine is 14.1.2.

Here’s my debug info:

SYSTEM INFO:
Obsidian version: v1.5.3
Installer version: v1.5.3
Operating system: Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103 23.1.0
Login status: logged in
Catalyst license: none
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 0
Plugins enabled: 0

RECOMMENDATIONS:
none

1 Like

MacOs version 14.2.1
Here’s my debug info:

SYSTEM INFO:
Obsidian version: v1.5.3
Installer version: v1.4.14
Operating system: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 23.2.0
Login status: logged in
Catalyst license: none
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none

Hm, so your MacOS is a little newer and your Obsidian installer version is a little older. I wouldn’t expect either of those to make a difference) you could try reinstalling Obsidian to get the latest installer version but I don’t think it’ll fix the issue.

Maybe a MacOS keyboard setting is making the difference? Maybe not — toggling MacOS’s “smart punctuation” and “smart quotes” settings (and resetting the sandbox vault) didn’t change the behavior.

What language input do you have set when you’re doing this?

That little underline under the ` (in your video) generally indicates you are in an alternative input mode.

Here I’m in Japanese - Romaji and typing the ` character (Apple Magic Keyboard - US). Then I switch to English. Then back to Japanese - Romaji.

CleanShot 2024-02-04 at 08.00.25

Not sure if that’s what’s happening in your case, but something to check.

1 Like

Good cach @ariehen I’m using French keyboard.
When I switch to US keyboard, it works.

Is there any possibility that dev fixes that?
I would realy LOVE this feature.

I think it’s worth filing a bug report.

@CawlinTeffid , are you using an English keyboard layout? If so, is the backtick a dead space character on your keyboard? I suspect it’s not, and that might be the issue.

On a Norwegian keyboard and I’m assuming on the French keyboard we can use the backtick key to build accented characters like èà and so on. To actually get the backtick we need two keypresses, the backtick key and the space key. If I remember correctly on the English keyboard, you just need to press the one key with the backtick, right?

And this might be why it doesn’t work in our context, but do work in yours and other keyboard having the same characteristics.

I filed a bug here, if you want to comment: Auto pair madown code syntax does not work on other keyboars than US (on MacOS)

I am using an English layout, and it does sound like that’s the issue.

@fran_cis_co Out of curiosity, is French set as your primary language in the macOS Language & Region settings? (I assume it is, but just checking)


There’s an old bug report here about the “deadkey backtick”, but it was fixed a while ago.

1 Like

It’s not, english is, but I have french keyboard layout.
Screenshot 2024-02-05 at 09.51.44

Same issue here:

  • Backtick and circonflex accent are dead keys on the French keyboard: they do not insert a full character (e.g. pressing the backtick key after e outputs è)

  • This causes issues when typing code, e.g. when toggling inline code in Obsidian (select text then press backtick).

I fixed the issue using this workaround:

  • Download French-backtick-circumflex.bundle (modified keyboard layout using Ukulele)
  • Copy it to /Library/Keyboard Layouts
  • Open Keyboard Preferences > Input Sources > French
  • Select the “French-code” keyboard layout

In Obsidian, you should now be able to toggle inline code when selecting text and pressing the backtick key.