An Obsidian plugin that cleans trailing whitespace in code blocks. Useful for code copied from terminals, CLI tools like Claude Code, Cursor, and other AI assistants.
When copying code from terminal applications or CLI tools, trailing whitespace is often included. This can cause rendering issues in Obsidian's markdown preview, especially with code blocks.
- Clean Code Block: Remove trailing whitespace from code blocks
- Select Code Block: Quickly select the entire code block at cursor
- Auto-clean on Paste (Optional): Automatically clean trailing whitespace when pasting
Open the command palette (Cmd/Ctrl + P) and search for:
- Clean code block (remove trailing whitespace): Cleans the code block at cursor, or cleans selected text
- Select code block: Selects the entire code block where your cursor is located
- With selected text: Cleans trailing whitespace in the selection
- Without selection, cursor in code block: Cleans the entire code block
- Without selection, cursor outside code block: Shows a notice
- Auto-clean on paste: When enabled, automatically removes trailing whitespace from all pasted content (disabled by default)
- Download
main.jsandmanifest.jsonfrom the latest release - Create a folder
paste-code-cleanerin your vault's.obsidian/plugins/directory - Copy
main.jsandmanifest.jsoninto the folder - Reload Obsidian
- Enable the plugin in Settings → Community plugins
- Clone this repository
- Run
npm install - Run
npm run build - Copy
main.jsandmanifest.jsonto your vault's.obsidian/plugins/paste-code-cleaner/directory
MIT