Better Code Blocks
Enhances code blocks with inline rendering, autocompletion, and more
Features
- Renders code blocks inline with
Minimal
orStandard
styles - Adds
copy
button for inline code blocks - Autocompletes code blocks on Enter
- Changes Select All to select the current code block
Settings
Setting | Options | Description |
---|---|---|
Autocompletion | Enabled , Disabled |
Enables/disables automatic completion of code blocks when Enter is pressed |
Rendering | Enabled , Disabled |
Enables/disables rendering of code blocks |
Behavior of Select All inside code block | Enabled , Disabled |
Changes the behavior of Select All while the cursor is inside code blocks |
Render layout | Minimal , Standard |
Changes the layout of rendered code blocks |
Corner style | Square , Round |
Changes the border style of rendered code blocks |
Excluded languages | (comma-separated list) |
Disables rendering of code blocks for specific languages |
Copy button behavior | Copy code , Copy code and fences |
Controls what's copied when the Copy Code button is clicked |
Hey all!
I frequently use code fences in my notes to keep track of snippets and documentation when I'm researching. But I find that the enclosing back-ticks kinda get in the way when I'm copying/modifying the code.
I also prefer to mess around in the note itself rather than using the preview pane.
So I created a plugin that "hides" the code fences and renders the code inline.
I added some other useful features like auto-completion of code blocks, a (hidden) copy button for quickly copying code, and a nifty hook to change "Select All" to select a code block instead if the cursor's currently inside one (you can "Select All" once more to get the normal behavior).
One of my goals with the rendering was to make it look as "native" as possible. So I was careful not to introduce extra vertical space when compared to the normal Joplin / CodeMirror rendering. I replaced the HTML of the fences (should be the same height ), but I didn't mess with the actual code lines.
If you don't like the rendering, you can disable it in settings and still get the auto-completion. I think the auto-completion alone is a really nice feature to have!
I added a bunch of CSS classes to the code block lines, so it should be pretty easy to customize everything to your liking.
Please let me know if you find bugs or have any feature requests! My CSS powers are extremely limited, so any styling contributions would also be greatly appreciated!