Collapsible Code Blocks

by Bradley Wyatt
5
4
3
2
1
Score: 52/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

61
stars
9,520
downloads
6
forks
560
days
51
days
51
days
3
total PRs
0
open PRs
0
closed PRs
3
merged PRs
13
total issues
5
open issues
8
closed issues
10
commits

Latest Version

2 months ago

Changelog

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.
Recent Files
6 years ago by Tony Grosinger
Display a list of most recently opened files
Hider
6 years ago by @kepano
Hide Obsidian UI elements such as tooltips, status, titlebar and more
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.
Code Styler
3 years ago by Mayuran Visakan
A plugin for Obsidian.md for styling codeblocks and inline code
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
CSS Editor
3 years ago by Zachatoo
Edit CSS snippets in Obsidian.
Editor Width Slider
3 years ago by @MugishoMp
With this plugin you can set the line width of the editor in obsidian.
Dynamic Views
a month ago by churnish
Obsidian plugin that adds elegant grid and masonry card views for Bases.
Numerals
4 years ago by RyanC
An obsidian plugin which turns a math code block into a full featured calculator
Codeblock Customizer
3 years ago by mugiwara
Codeblock Customizer plugin for Obsidian
Beautitab
3 years ago by Andrew McGivery
A plugin for Obsidian.MD that creates a customizable new tab view with beautiful backgrounds, quotes, search, and more.
Collapse All
5 years ago by Nathonius
Icon Shortcodes
5 years ago by AidenLx
Obsidian Plugin: Insert emoji and custom icons with shortcodes
Ninja Cursor
4 years ago by vorotamoroz
Floating Search
4 years ago by Boninall
A plugin for searching text by using Obsidian default search view.
2Hop Links Plus
3 years ago by Tokuhiro Matsuno, L7Cy
Related links up to 2 hops away are displayed in a card format.
Core Search Assistant
5 years ago by qawatake
An Obsidian plugin to enhance built-in search: keyboard interface, card preview, bigger preview
ABC Music Notation
6 years ago by Til Blechschmidt
Plugin which renders music notations from code blocks
Background Image
3 years ago by shmolf
Rich Links
5 years ago by dhamaniasad
Emoji Magic
4 years ago by simplgy
Makes it easier to add emojis using an improved keyword search
ProgressBar
4 years ago by Wei Zhang
Code block plugin for Obsidian generating a progress bar
Refresh Preview
2 years ago by mnaoumov
Obsidian Plugin that allows to refresh any view without reopening it.
Advanced Codeblock
4 years ago by Lijyze
An obsidian plugin that give additional features to code blocks.
Font Size Adjuster
3 years ago by Ryota Ushio
An Obsidian.md plugin to adjust font size via commands.
Embedded Code Title
5 years ago by tadashi-aikawa
It is an Obsidian plugin which can embeds title to code blocks.
Status Bar Organizer
3 years ago by Kacper Darowski
Arrange and hide status bar elements.
Fontsource
2 years ago by Ayuhito
A plugin to load custom fonts from Fontsource into Obsidian.
Auto Split
5 years ago by James Sartelle
Open notes with side-by-side editor & preview
Ace Code Editor
a year ago by RavenHogWarts
An enhanced code editor using Ace editor
HK Code Block
3 years ago by Heekang Park
Obsidian plugin developed by Heekang Park; Make code block looking good on reading view
MLIR Syntax Highlight
3 years ago by Lewuathe
Node Auto Resize
2 years ago by Boninall
Email Reader
3 years ago by Pulsovi
Zen Mode
2 years ago by paperbenni
Blur
3 years ago by @gapmiss
A plugin for creating obfuscated blocks of text in Obsidian.md
CodeBlock Tabs
3 years ago by Jemin Mau
Create tab group for contiguous codeblocks.
Canvas Card Background Remover
3 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.
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.
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
Link Preview
2 years ago by Felipe Tappata
Obsidian plugin that previews external links on hover.
Force Read Mode
2 years ago by al3xw
CSV Codeblock
3 years ago by elrindir
Plugin for obsidian to render csv syntax in codeblocks.
Full Screen Toggle
3 years ago by Donkey Pacific
Fullscreen toggle plugin across all platforms for Obsidian.
Tokei
3 years ago by HiroMike
A simple clock for Obsidian
Todo.txt Codeblocks
3 years ago by Benjamin Nguyen
Manage your tasks inside Obsidian codeblocks according to the Todo.txt specification.
Explorer Colors
2 years ago by Scott Van der Zwet
Set cascading colors for files and folders in Obsidian.
Hugo preview obsidian
4 years ago by fzdwx
:superhero: Hugo preview in obsidian
Auto Hide Cursor
3 years ago by Mo Ismat
A simple plugin for https://obsidian.md
Shrink pinned tabs
2 years ago by Nicolas Lœuillet
Obsidian plugin to shrink pinned tabs in order to save screen space
Additional Icons
3 years ago by Matthew Turk
Add additional iconsets to Obsidian
Minitabs
3 years ago by ssjy1919
Obsidian tabs
Color cycler
3 years ago by Taylor Brennan
Plugin for Obsidian to dynamically change the accent color
MP Preview
a year ago by Yeban
一个帮助你快速将 Obsidian 笔记转换为微信公众号格式的插件。
Context Command Hider
2 years ago by Mara-Li
This plugin allows you to hide every command from the Obsidian's right-click context menu.
Auto Reading Mode
3 years ago by Kelvin Cao
Codeblock Template
3 years ago by Super10
A template plugin that allows for the reuse of content within Code Blocks!一个可以把Code Block的内容重复利用模板插件!
Theme by Folder
a year ago by Jinmu Go
Automatically switch Obsidian themes based on the folder of the opened note
Mention Autocomplete
2 months ago by Darren Zheng
Type `@` to instantly search and link any note in your vault — with full-text search, rendered preview, and smart sentence extraction.
Tag Formatter
3 years ago by snsvrno
Configurable Obsidian plugin that hides parent tags.
Attachment Organizer
2 months ago by kiteruunner
Automatically organize attachments into zone-based folders with conflict detection and batch operations
Theme Controller
2 years ago by Binaris
Set when and how the themes will be displayed
Hide Commands in Menu
2 years ago by bomian98
Obsidian Plugin, hide different commands in different menus.
YAML Table
a year ago by dainakai
Backgroundset
2 years ago by daonali
similar as vscode background
Reveal Folded
a year ago by d7sd6u
Adds a command that reveals current file while collapsing every other tree item
Command Line
2 years ago by Steven Stallion
Copy command lines from your notes to the clipboard.
Dayframe
2 months ago by Ganessh Kumar R P
🖼️ like a picture frame but for your daily notes.
Replace Pencil
a year ago by penyt
🐧 An Obsidian plugin that can easily replace the custom variable in the code block.
Collapse Linked Mentions
2 years ago by Nathan K.
Card Forge
7 months ago by Carl Sverre
Create printable cards from your notes!
Hide Traffic Lights
6 months ago by Ben Phillips
Code Blocks commands
a year 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
Universal UI Translator
a month ago by feifei
ICOR for Life - Interface
a month ago by Paperless Movement S.L.
The vault's chrome in one place: hide the ribbon and Obsidian's own controls, and give any folder a colour, an icon and a label. Writes no CSS; the INKLINE theme draws it. Part of the ICOR for Life suite.