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

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.