bladeacer's Obsidian Snippets Collection
This repository is a collection of CSS snippets for the note taking application Obsidian.
Why another snippet collection?
There are quite a few snippet collections by the Obsidian community. Here are some of the reasons I decided to make my own:
- I do not really know where to begin to contribute to all of them
- I wish to showcase some of the more niche snippets I found or made, especially those from my theme flexcyon.
- Utilities like the bundled snippet extraction script can be used in other snippet collections
Snippets in this repository
From flexcyon
View this directory for the snippets
- Colour Accessibility
- ASCII Art in new tab
- Vim Mode Status
- Callouts
- Callout color
- Callout extended color
- No Icon/Background
- Horizontal/vertical alignment
- Vertical alignment
- Text transform
- and many others...
Extracting your own snippets
Enclose your snippet(s) of interest like this
/* obsi-snip-coll start: font-size */
/* @description: Enlarges the UI font size. */
body {
font-size: 1.2rem;
}
/* obsi-snip-coll end */
The optional name after start: becomes the snippet name. The
@description comment is read from the source and written into the
generated CSS snippet, where the
CSS Snippet Descriptions
plugin can display and edit it too. Descriptions also appear in the
generated markdown file.
Make use of the extraction script.
Ensure you have Python installed (check with which python, install it on Windows)
You do not need a virtual environment for the script, it calls Python's standard library only.
Follow the supported .env formats to configure target sources:
A SOURCE_PATH may point at a single CSS/SCSS file or at a project folder.
Sources are discovered recursively in conventional folders (scss, sass,
src, styles, style, source), with .scss/.sass preferred over a
sibling .css. SCSS is compiled with a local Sass binary when available,
otherwise by a lightweight standard-library converter. Unsupported SCSS
constructs are skipped; keep a compiled .css sibling if you need those.
cp .env.dev-2 .env
vim .env
Set permissions if you are on Linux.
chmod +x ./extract-snippets.py
Run the script.
./extract-snippets.py # interactive mode
./extract-snippets.py -y # auto-accept weak matches
./extract-snippets.py -n # non-interactive, use defaults
./extract-snippets.py -ny # fully automatic mode
./extract-snippets.py --validate # check caches and files
./extract-snippets.py --rescan # rescan CSS/SCSS, keep the caches
./extract-snippets.py --clear-cache # throw away caches and rebuild
./extract-snippets.py --edit # pick a snippet to rename/redescribe/categorize
./extract-snippets.py --edit rows -n --name stripe --description 'New text' --category callouts
CLI options:
-h,--help- show usage with examples-y,--yes- auto-accept weak matches without prompting-n,--non-interactive- non-interactive mode, use defaults for all prompts (no stdin needed)--validate- cross-check caches against files: paths, categories,@descriptionheaders and description drift; exit on issues-e,--env ENV_PATH- path to.envfile (default:./.env)--clear-cache- emptyindex.jsonandmetadata.jsonbefore running; both are caches that can be deleted at any time and are rebuilt from sources/disk--rescan- rescan the configured CSS/SCSS sources while keeping the caches, reconciling changes and duplicate snippet blocks. Descriptions are read from each snippet's canonical CSS/SCSS block (SCSS wins over a stale compiled CSS file), and the cache is refreshed whenever a description is added or changed. This is the normal way to pick up source edits without losing cached names/categories-E,--edit [NAME]- edit a snippet's name, description and category; with no name you get a picker. Edits update the CSS header, markdown, caches and (where possible) the@descriptionin the source file; renaming or re-categorizing also moves the files and updates the index entry--name,--description,--category- values for--edit(used directly with-n, otherwise as prompt defaults)--no-unminify- do not unminify detected minified CSS sources--no-scss- do not prefer/convert SCSS sources
Descriptions and caches
A @description comment inside a snippet is the source of truth: it is copied
into the generated CSS snippet and markdown, and is what the
CSS Snippet Descriptions
plugin displays. Keep it to one line of plain text.
In a plain CSS source (a theme file or a standalone snippet), use a normal comment inside the snippet block:
/* obsi-snip-coll start: alternating-rows */
/* @description: Adds alternating row colors. */
.table tr:nth-child(even) {
background: var(--background-secondary);
}
/* obsi-snip-coll end */
In an SCSS/Sass source, Sass removes ordinary /* ... */ comments from
compressed output, so make both the snippet markers and the description
loud comments (/*! ... */):
/*! obsi-snip-coll start: alternating-rows */
/*! @description: Adds alternating row colors. */
.table {
tr:nth-child(even) { background: var(--background-secondary); }
}
/*! obsi-snip-coll end */
If your preprocessor/build step emits canonical /* ... */ comments in the
compiled CSS (as flexcyon's scripts/build.js does), the generated snippets
use the canonical form. The extractor accepts both forms, so any preprocessor
that preserves the description comment in the emitted CSS works.
If a source block has no description, the interactive run prints the full
snippet context and prompts for one. The answer is written back into the
canonical CSS or SCSS file for that snippet, so it survives a cache clear.
With -n the context is still shown but no prompt is made. A description
added directly to a generated snippet file is picked up on the next rescan
when the source block has none.
Uncategorized snippets also prompt for a category in interactive mode. The
available categories are printed as a numbered list; enter a number to reuse
one or type a new name to create it. The chosen category moves the CSS/markdown
files and updates index.json and metadata.json. With -n, the current
category is kept.
index.json and metadata.json are caches, not the source of truth.
Each metadata entry also stores the source_file and source_kind of the
snippet block, so prompted descriptions and --edit changes go back to the
exact CSS/SCSS file that owns the block. A source file containing the same
named block wins over the compiled CSS. You can delete the caches (or run
--clear-cache) at any time; extraction rebuilds them from the sources and
the snippet files already on disk.
Minified and SCSS sources
Minified CSS is detected automatically and unminified before scanning, so
extracted snippets are readable and formatted with line breaks at ; and
{/} boundaries. Use --no-unminify to opt out.
Source preference
A compiled file such as theme.css is expanded to its project's sources in
this order:
.sass/.scssfiles in subfolders that contain snippet blocks.cssfiles in subfolders- the compiled
theme.cssfallback
This keeps generated CSS readable instead of minified. Use --no-scss to
force scanning CSS files only.
Compiled themes are minified, so blocks are also matched by name. A later copy with the same name is skipped when its CSS is identical or when it is the compiled fallback. Same-name files with different CSS are kept; only identical stale copies are pruned, with the cached category taking priority.
How are my snippets checked?
The script never relies on line numbers alone, it follows this hierarchy to identify and manage snippets:
- Minified CSS Content Match - compares minified (comments + whitespace removed) content
- Exact Index Key Match - matches by source name, file name, and filtered line range
- Line Count + Proximity Match - same line count within 30 lines auto-update; beyond 30 prompts or skipped depending on flags (
-y,-n) - On-disk Content Match - scans existing snippet files when the index is stale or cleared
- Name Match in Subfolder - updates the existing categorized copy when a minified block's content changed
- Fallback and Prompting - no match found, interactive prompt for new entry
Why I made the script
A standardised, theme and vault agnostic means of extracting CSS snippets into my CSS snippet collection. I find it useful for extracting and managing snippets from various sources.
Troubleshooting
Error message, crash when metadata after exiting and re-entering metadata for new snippets.
Remove snippets/index.json. When you run the script again, it will generate an
updated version in its place.
Contributing
PRs, Issues, Bug Reports are welcome. I hope that the script and snippets would be useful to the community :D
Recommended snippets to install
- HandaArchitect / obsidian-banner-snippet
Other snippet collections
Click to expand/collapse
- #appearance - Obsidian discord
- Obsidian CSS Quick Guide (forum) (mostly about using the inspector) -
- CSS Variables at Obsidian Dev Docs
- replete / obsidian-minimal-theme-css-snippets
- SlRvb's snippets collection | Guide
- zamsyt / obsidian-snippets
- ElsaTam / Obsidian-Stuff
- KuiyueRO / Obsidian-Miner
- sailKiteV / Obsidian-Snippets-and-Demos
- TfTHacker / DashboardPlusPlus
- eb2ai / My-Checklists-and-Icons
- xhuajin / obsidian-sidenote-callout
- efemkay / Obsidian Modular CSS Layout
Credits
- r-u-s-h-i-k-e-s-h / Obsidian CSS Snippets
- narwhai / CSS Snippet Descriptions - for inspiring the in-source
@descriptionformat - The wonderful
#appearancecommunity on the Obsidian Members' Group Discord
How to Install
- Download the repository ZIP below
- Unzip it and find the CSS snippet file
- Move the CSS file into your vault's
.obsidian/snippets/folder - Open Obsidian → Settings → Appearance → CSS Snippets → Enable it
Stats
Stars
9
Forks
0
License
MIT
Last updated 13h ago