Collapsible Code Blocks

by Bradley Wyatt
5
4
3
2
1
Score: 36/100

Description

Category: Note Enhancements

The Collapsible Code Blocks plugin improves the readability and organization of notes in Obsidian by allowing users to collapse long code blocks in preview mode. This helps reduce visual clutter when working with large snippets of code. The plugin offers smooth expand/collapse animations, customizable toggle icons, and control over how many lines remain visible when collapsed.

Reviews

No reviews yet.

Stats

54
stars
6,322
downloads
4
forks
408
days
108
days
112
days
1
total PRs
1
open PRs
0
closed PRs
0
merged PRs
9
total issues
2
open issues
7
closed issues
0
commits

Latest Version

4 months ago

Changelog

Fixed

  • #8 Collapsed code blocks become "stuck" in that state and "traps" the cursor inside.

README file from

Github

Collapsible Code Blocks

Github All Releases

Make code blocks collapsible in preview mode with customizable collapse/expand behavior and horizontal scrolling options. This plugin enhances the readability of your notes by allowing you to collapse long code blocks when you don't need to see their full content.

Demo

Features

Code Collapsed

  • Toggle code blocks between collapsed and expanded states
  • Customizable collapse/expand icons
  • Optional horizontal scrolling for code blocks
  • Configure number of visible lines when collapsed
  • Default collapse state setting
  • Control if a code block should be expanded or collapsed on a per-note basis by setting code-blocks to collapsed or expanded in the frontmatter
  • Smooth animations for collapse/expand transitions
  • Maintains proper layout with surrounding content

Installation

  1. Open Obsidian Settings
  2. Navigate to Community Plugins and disable Safe Mode
  3. Click Browse and search for "Collapsible Code Blocks"
  4. Install the plugin
  5. Enable the plugin in your Community Plugins list

Usage

Once installed, code blocks in preview mode will automatically have a toggle button in their top-left corner. You can:

  • Click the toggle button to collapse/expand the code block
  • Use the keyboard (Enter or Space) when the toggle button is focused
  • Configure default behavior in plugin settings

Code Block Interaction

  • Click the toggle button (▼/▶) to collapse or expand the code block
  • When collapsed, only the specified number of lines will be visible
  • Horizontal scrolling can be enabled/disabled globally
  • Code blocks maintain their collapsed/expanded state when switching between notes

Settings

The plugin offers several customization options:

  • Default Collapsed State: Choose whether code blocks should start collapsed
  • Collapse/Expand Icons: Customize the icons shown for collapse/expand states
  • Horizontal Scrolling: Toggle horizontal scrolling for code blocks
  • Collapsed Lines: Set how many lines remain visible when collapsed
  • Frontmatter Setting: Set the frontmatter key to control the default state of code blocks

Frontmatter Setting

Set a note to always have code blocks expanded or collapsed by default by adding the following to the note's frontmatter (note: this will override the global default setting):

Collapsed
code-blocks: collapsed

Code Collapsed

Expanded
code-blocks: expanded

Code Expanded

Examples

Here's how a code block appears with the plugin enabled and the code block expanded: Code Expanded

Here's how a code block appears with the code collapsed and set to show 0 lines. Code Collapsed

Support

If you encounter any issues or have suggestions:

Development

Want to contribute? Here's how to get started:

  1. Clone the repository:

    git clone https://github.com/bwya77/collapsible-code-blocks.git
    
  2. Install dependencies:

    npm install
    
  3. Start development build:

    npm run dev
    

Testing Your Changes

  1. Create a symbolic link to your vault's .obsidian/plugins/ directory
  2. Enable the plugin in Obsidian's community plugins settings
  3. Use the developer console (Ctrl+Shift+I) to debug

License

MIT License

Similar Plugins

info
• Similar plugins are suggested based on the common tags between the plugins.
Homepage
5 years ago by mirnovov
An Obsidian plugin that opens a specified note, canvas, or workspace on startup, instead of the most recent one.
Hider
5 years ago by @kepano
Hide Obsidian UI elements such as tooltips, status, titlebar and more
Code Styler
3 years ago by Mayuran Visakan
A plugin for Obsidian.md for styling codeblocks and inline code
Iconic
2 years ago by Holo
Customize your icons and colors directly from the Obsidian UI, including tabs, files & folders, bookmarks, tags, properties, and ribbon commands.
Convert url to preview (iframe)
6 years ago by FHachez
Plugin for Obsidian.md to convert a selected URL to an iframe.
Link Embed
4 years ago by SErAphLi
This plugin allow you to convert URLs in your notes into embeded previews.
Obsidian Columns
4 years ago by Trevor Nichols
Editor Width Slider
3 years ago by @MugishoMp
With this plugin you can set the line width of the editor in obsidian.
CSS Editor
3 years ago by Zachatoo
Edit CSS snippets in Obsidian.
Numerals
3 years ago by RyanC
An obsidian plugin which turns a math code block into a full featured calculator
Collapse All
5 years ago by Nathonius
Icon Shortcodes
4 years ago by AidenLx
Obsidian Plugin: Insert emoji and custom icons with shortcodes
Beautitab
2 years ago by Andrew McGivery
A plugin for Obsidian.MD that creates a customizable new tab view with beautiful backgrounds, quotes, search, and more.
Codeblock Customizer
3 years ago by mugiwara
Codeblock Customizer plugin for Obsidian
Floating Search
3 years ago by Boninall
A plugin for searching text by using Obsidian default search view.
Ninja Cursor
4 years ago by vorotamoroz
Core Search Assistant
4 years ago by qawatake
An Obsidian plugin to enhance built-in search: keyboard interface, card preview, bigger preview
Rich Links
5 years ago by dhamaniasad
2Hop Links Plus
3 years ago by Tokuhiro Matsuno, L7Cy
Related links up to 2 hops away are displayed in a card format.
ABC Music Notation
5 years ago by Til Blechschmidt
Plugin which renders music notations from code blocks
Background Image
3 years ago by shmolf
Emoji Magic
3 years ago by simplgy
Makes it easier to add emojis using an improved keyword search
Advanced Codeblock
4 years ago by Lijyze
An obsidian plugin that give additional features to code blocks.
ProgressBar
3 years ago by Wei Zhang
Code block plugin for Obsidian generating a progress bar
Embedded Code Title
5 years ago by tadashi-aikawa
It is an Obsidian plugin which can embeds title to code blocks.
Status Bar Organizer
2 years ago by Kacper Darowski
Arrange and hide status bar elements.
Font Size Adjuster
2 years ago by Ryota Ushio
An Obsidian.md plugin to adjust font size via commands.
Refresh Preview
2 years ago by mnaoumov
Obsidian Plugin that allows to refresh any view without reopening it.
Auto Split
4 years ago by James Sartelle
Open notes with side-by-side editor & preview
MLIR Syntax Highlight
3 years ago by Lewuathe
HK Code Block
3 years ago by Heekang Park
Obsidian plugin developed by Heekang Park; Make code block looking good on reading view
Fontsource
2 years ago by Ayuhito
A plugin to load custom fonts from Fontsource into Obsidian.
Email Reader
3 years ago by Pulsovi
Ace Code Editor
a year ago by RavenHogWarts
An enhanced code editor using Ace editor
Node Auto Resize
2 years ago by Boninall
CodeBlock Tabs
3 years ago by Jemin Mau
Create tab group for contiguous codeblocks.
Canvas Card Background Remover
2 years ago by luxmargos
This Obsidian plugin allows you to make the background of cards transparent in the Canvas for specific embed types, including Image (png), Canvas, and even Markdown.
File Explorer Markdown Titles
5 years ago by Dylan Elliott
Obsidian Plugin that adds the the markdown title within your notes to the file explorer
Blur
3 years ago by @gapmiss
A plugin for creating obfuscated blocks of text in Obsidian.md
Obsidian Stylist
3 years ago by ixth
Obsidian plugin that allows to add classes and styles on markdown blocks
Auto Folder Collapse
2 years ago by Dario Casciato
A plugin for Obsidian that automatically collapses all child folders when you collapse a parent folder. This helps keep your file explorer organized and clutter-free.
Enlightenment
4 years ago by ryanjamurphy
Pay attention to what you're paying attention to.
Link Preview
a year ago by Felipe Tappata
Obsidian plugin that previews external links on hover.
Zen Mode
a year ago by paperbenni
CSV Codeblock
3 years ago by elrindir
Plugin for obsidian to render csv syntax in codeblocks.
Command Palette--
4 years ago by qawatake
An Obsidian plugin to provide a command palette without unwanted commands
Tokei
3 years ago by HiroMike
A simple clock for Obsidian
Full Screen Toggle
2 years ago by Donkey Pacific
Fullscreen toggle plugin across all platforms for Obsidian.
Hugo preview obsidian
3 years ago by fzdwx
:superhero: Hugo preview in obsidian
Todo.txt Codeblocks
3 years ago by Benjamin Nguyen
Manage your tasks inside Obsidian codeblocks according to the Todo.txt specification.
Auto Hide Cursor
3 years ago by Mo Ismat
A simple plugin for https://obsidian.md
Additional Icons
2 years ago by Matthew Turk
Add additional iconsets to Obsidian
Explorer Colors
a year ago by Scott Van der Zwet
Set cascading colors for files and folders in Obsidian.
Minitabs
2 years ago by ssjy1919
Obsidian tabs
Force Read Mode
a year ago by al3xw
Auto Reading Mode
3 years ago by Kelvin Cao
Shrink pinned tabs
2 years ago by Nicolas Lœuillet
Obsidian plugin to shrink pinned tabs in order to save screen space
Color cycler
2 years ago by Taylor Brennan
Plugin for Obsidian to dynamically change the accent color
Codeblock Template
3 years ago by Super10
A template plugin that allows for the reuse of content within Code Blocks!一个可以把Code Block的内容重复利用模板插件!
MP Preview
a year ago by Yeban
一个帮助你快速将 Obsidian 笔记转换为微信公众号格式的插件。
Context Command Hider
a year ago by Mara-Li
This plugin allows you to hide every command from the Obsidian's right-click context menu.
Theme toggle
a year ago by @gapmiss
Obsidian.md plugin … adds a ribbon icon and command for toggling between dark & light theme modes.
Tag Formatter
2 years ago by snsvrno
Configurable Obsidian plugin that hides parent tags.
Theme by Folder
a year ago by Jinmu Go
Automatically switch Obsidian themes based on the folder of the opened note
Backgroundset
a year ago by daonali
similar as vscode background
Wheel Tab Switcher
a year ago by 22-2
Switch between Obsidian Tabs using your mouse wheel when hovering over tab headers.
Theme Controller
a year ago by Binaris
Set when and how the themes will be displayed
Smooth Cursor
a year ago by Busyo
Obsidian光标美化插件
YAML Table
a year ago by dainakai
Reveal Folded
a year ago by d7sd6u
Adds a command that reveals current file while collapsing every other tree item
Hide Commands in Menu
a year ago by bomian98
Obsidian Plugin, hide different commands in different menus.
Collapse Linked Mentions
2 years ago by Nathan K.
Command Line
a year ago by Steven Stallion
Copy command lines from your notes to the clipboard.
Code Blocks commands
8 months ago by dragonish
Provide commands to insert code blocks with markup, and support triggering commands with backticks.
Close Window When Empty
2 years ago by Taylor Jadin
Hide Traffic Lights
a month ago by Ben Phillips
Hides macOS traffic light buttons for a distraction-free experience. Hover over the top-left corner to reveal them.
Replace Pencil
10 months ago by penyt
🐧 An obsidian plugin that can easily replace the custom variable in the code block.
Card Forge
2 months ago by Carl Sverre
Convert notes into printable cards.