Evie Hartman36 downloadsRemoves leading indentation when copying from indented code blocks.
An Obsidian plugin that lets you copy indented code blocks as if they're not indented, letting you fold code blocks in lists while preserving their intended structure.
In Obsidian, when you copy a code block that has leading indentation, the copied content will include that indentation. This can be annoying when you want to paste the code elsewhere, like into a command line. (No one likes deleting leading spaces inside a terminal command.)
Most of the time, the answer is to just not indent code blocks, but what if you want to be able to fold the entire code block nicely inside a list?
I couldn't find any other plugins that simply excluded the code block's indentation from the copying functionality, so I made one.
🔴🔴(note: see the section on indented code blocks at the end)🔴🔴
When you copy a code block using the built-in copy functionality (clicking on the text or icon in the top right corner of your code block), this plugin will:
It works with:
I hope this adds some ease to the document organization you want!
Before (indented code block):
```javascript
function hello() {
console.log("Hello, world!");
}
```
What you'll paste in default Obsidian:
function hello() {
console.log("Hello, world!");
}
What you'll paste with this plugin:
function hello() {
console.log("Hello, world!");
}
Indented code blocks only seem to render as such when directly underneath a list item (bullet, checkbox, number). If simply indented, they won't. For example:
Text
foo
...even with text directly above it (yes, even indented text)
bar
(it looks a bit different on Obsidian - here on Gthub, it doesn't even want to line break.)
foo bar
Numbers and checkboxes work too. In fact, it even seems to work even if there are blank empty unindented newlines between the list item and the indented code block. (Since folding code blocks inside lists is the use case I needed this for, I love that this native Obsidian functionality makes it even more flexible for that.)dist folder contentsmain.js and manifest.json in an .obsidian/plugins/copy-indented-code-blocks/ directory in your vaultCopy this repo's URL into the plugin and enjoy!
npm install
npm run build
The built files will be in the dist/ folder.