"Toggle code block" command that wraps the selection with three backticks

Use case or problem

There is a command “Toggle code” but no “Toggle code block” command. I use code blocks with three backticks much more frequently than single backtick code lines. Typing a backtick on a German keyboard is a pain.

Proposed solution

Have a command “Toggle code block” like “Toggle code” but with three backticks and not one. It should work with selected text and wrap it with backticks.

Current workaround (optional)

  1. Cut the selected text, insert the 6 backticks with a template, go back, paste the code.
  2. Using a custom wrapper in the Text Format plugin:

Related feature requests (optional)

This feature request was a second request mentioned in "Toggle code" works like "Toggle Italic" and "Toggle Bold" + "Toggle Code Block" but it’s not yet implemented.

If you are willing to install the Templater plugin, you could try using this. It’s set for a css code block, but can be changed or duplicated to whatever is needed.

Thanks @ariehen , yes I had tried templater but with a simpler template. But just now I stumbled upon the excellent Text Format plugin and its custom wrapper function. That works really well and I can have wrapper for all my programming languages. I updated my post with a screenshot.

There is already, block operators follow “insert command” patterns.
In this case “insert code block”

1 Like