I write a lot about coding (unsurprisingly) and frequently find myself wishing that I used a markdown editor instead of Redactor, particularly for easier inline code styles
. Still, there are plenty of things which irritate me about markdown too, so I've just forged on, but today I discovered two useful tips:
- Redactor has an inline styles plugin that includes inline
<code>
tags; - There is an API for adding keyboard shortcuts.
So I know have both set up here, and figured I'd share what that looks like. As always, you want to edit your Redactor config files in the standard Craft -> Config -> Redactor
folder. To add the plugin, just use:
{ "plugins": ["inlinestyles"] }
If you want to add a keyboard shortcut, then you can supplement it with:
{ "plugins": ["inlinestyles"], "shortcutsAdd": { "alt+c, alt+`": { "api": "module.inline.format", "args": "code" } } }
Personally, I wasn't sure which keyboard shortcut would work best, so I've added two, but you can do any key combination (by the looks of things). I've also added shortcuts for <sup>
and <sub>
elements too 👍
Note: Unfortunately, it looks like the API method for toggling inline elements (type: toggle
) doesn't work with <code>
tags. Not sure why, as it works with everything else by default 🤷♂️