Style Context

by Moy
5
4
3
2
1
Score: 40/100

Description

An Obsidian plugin that publishes runtime context as CSS classes and variables. It turns things like your current theme and vault image paths into predictable hooks for your own custom CSS snippets.

Reviews

No reviews yet.

Stats

10
stars
816
downloads
1
forks
17
days
16
days
16
days
3
total PRs
2
open PRs
0
closed PRs
1
merged PRs
0
total issues
0
open issues
0
closed issues
56
commits

Latest Version

17 days ago

Changelog

[0.3.5] 2026-08-07

🐛 Fixed

  • Appearance slider values: Read the current setting value when rendering each slider so mobile Settings pages show the latest Dark appearance value after navigating away and back.
  • Frameless title bar background: Make the top-right title bar button container transparent in non-fullscreen frameless windows.
  • Dynamic list button layout: Clear stale rule-row classes from Add path rule and Add image variable rows after dynamic list updates.

🐛 修复

  • 外观滑块数值:每次渲染滑块时读取当前设置值,修复移动端离开并重新进入 Dark 外观页面后仍显示旧值的问题。
  • 无框窗口标题栏背景:让非全屏无框窗口右上角的标题栏按钮容器保持透明。
  • 动态列表按钮布局:动态列表更新后清理「添加路径规则」和「添加图片变量」按钮行残留的规则行 class。

[0.3.4] 2026-08-07

🚀 Added

  • Light/dark background images: Optionally configure separate image values and appearance settings for theme-light and theme-dark windows, while retaining the existing global configuration as the default.
  • Mode-aware random backgrounds: Random background selection now updates the image value for the current light or dark mode when separate backgrounds are enabled.

⚡ Changed

  • Background settings layout: Keep each image value directly paired with its corresponding Appearance page.
  • Startup randomization default: Keep Choose a random background image on startup disabled by default.

🚀 新增

  • 明暗模式背景图:可分别为 theme-lighttheme-dark 窗口设置图片值与外观,同时保留原有全局配置作为默认配置。
  • 按模式随机背景:启用明暗模式背景后,随机背景图片只更新当前明暗模式对应的图片值。

⚡ 变更

  • 背景设置布局:每个 Image value 都会紧跟对应的 Appearance 设置。
  • 启动随机背景默认值:默认关闭「Choose a random background image on startup」。

[0.3.3] 2026-08-07

🚀 Added

  • Slider reset controls: Add localized reset buttons to image opacity and every background filter slider, restoring each control to its canonical default value.

⚡ Changed

  • Appearance organization: Keep opacity and blend mode under Display, reorder filters for faster adjustment, and move size, position, and repeat into a final Layout group while hiding the unused Attachment control.
  • Status bar surface: Preserve the theme's status bar background instead of forcing it transparent when the built-in canvas background is enabled.

🐛 Fixed

  • Detached Settings synchronization: Publish theme classes, image variables, and background properties across the main window, independent Settings window, and workspace popouts so live changes affect every window.
  • First-open image previews: Publish image variables directly to the detached Settings document during its first render, eliminating the focus timing race that left previews empty until an image was selected again.

🚀 新增

  • 滑块重置控件:为图片不透明度和所有背景滤镜滑块添加本地化重置按钮,可将各项恢复为统一定义的默认值。

⚡ 变更

  • 外观设置整理:在「显示」中仅保留不透明度与混合模式,重新排列滤镜顺序,并将尺寸、位置和重复方式移至末尾的「布局」组,同时隐藏未使用的「附着方式」控件。
  • 状态栏表面:启用内置画布背景时不再强制状态栏透明,保留当前主题定义的状态栏背景。

🐛 修复

  • 独立设置窗口同步:在主窗口、独立设置窗口和工作区弹出窗口之间同步发布主题类、图片变量与背景属性,确保实时调整作用于所有窗口。
  • 首次打开图片预览:独立设置窗口首次渲染时直接向其文档发布图片变量,消除因窗口焦点切换时序导致的空白预览,无需重新选择图片。

[0.3.2] 2026-08-07

🚀 Added

  • Background image previews: Show a compact source preview beside the Image value controls and a full Appearance preview that reflects the configured opacity, blend mode, sizing, positioning, repeat, and filters.

⚡ Changed

  • Efficient live updates: Apply Appearance changes only to the background service and update only CSS custom properties whose values changed, avoiding unrelated resource, theme, and note-path work while adjusting controls.

🐛 Fixed

  • Official review compliance: Move background-layer rules into the static plugin stylesheet and publish runtime background and resource values through CSS custom properties, eliminating forbidden runtime <style> elements and lint suppressions.
  • Image value guidance: Explain that bare custom properties such as --image must be wrapped as var(--image), with localized guidance to copy a ready-to-use variable from its preview.
  • Responsive Image value layout: Keep the input and shuffle button together, place the preview and validation feedback on separate rows, and wrap long CSS image examples within narrow settings panes.

🚀 新增

  • 背景图片预览:在「图片值」控件旁显示紧凑的源图片预览,并在「外观」页面显示完整预览,实时反映不透明度、混合模式、尺寸、位置、重复方式和滤镜设置。

⚡ 变更

  • 高效实时更新:调整外观控件时仅应用背景服务,并只更新值发生变化的 CSS 自定义属性,避免重复执行无关的资源变量、主题和笔记路径处理。

🐛 修复

  • 官方审核合规性:将背景图层规则迁移至插件静态样式表,并通过 CSS 自定义属性发布运行时背景与资源值,彻底移除审核禁止的运行时 <style> 元素和 lint 规则禁用指令。
  • 图片值输入指引:输入 --image 等裸 CSS 自定义属性时,明确提示使用 var(--image) 包裹,并引导用户点击预览复制可直接使用的变量值。
  • 图片值响应式布局:保持输入框与随机按钮位于同一行,将预览和校验提示分别放置在后续行,并确保窄设置面板中的长 CSS 图片示例能够正常换行。

[0.3.1] 2026-08-07

🚀 Added

  • Flexible background image values: Accept complete CSS background-image expressions such as var(--image), remote url(...) values, and gradients, with syntax validation and a privacy notice for remote image hosts.

⚡ Changed

  • Ready-to-use image references: Store the built-in background as an imageValue and make random selection insert var(--name) so copied local image references can be pasted directly.
  • Obsidian DOM helpers: Create dynamic style and diagnostics elements with Obsidian's createEl and createDiv helpers for API compliance.

🚀 新增

  • 灵活的背景图片值:支持填写完整的 CSS background-image 表达式,例如 var(--image)、远程 url(...) 和渐变,并提供语法校验与远程图片隐私提示。

⚡ 变更

  • 可直接使用的图片引用:内置背景改为保存 imageValue,随机选择会直接填入 var(--name),复制的本地图片引用可以直接粘贴使用。
  • Obsidian DOM 辅助方法:动态样式和诊断元素改用 Obsidian 的 createElcreateDiv,符合官方 API 规范。

[0.3.0] 2026-08-06

🚀 Added

  • Built-in background image: Apply an enabled local image variable to the Obsidian canvas with random selection, opacity, blend mode, size, position, repeat, and attachment controls.
  • Background filters: Adjust the background image layer with CSS filters — brightness, contrast, saturation, grayscale, sepia, invert, hue rotate, and blur — from the new Appearance sub-page.

⚡ Changed

  • Declarative settings on Obsidian 1.13: The settings tab now uses the declarative settings API introduced in Obsidian 1.13.0, raising the minimum required Obsidian version to 1.13.0. Background display options (opacity, blend mode, size, position, repeat, attachment) and filters are grouped together in an Appearance sub-page under Background image.

🐛 Fixed

  • Resource variable publishing: Publish vault resource variables in a dedicated stylesheet so they remain available to computed-style consumers without modifying the html element's inline style.
  • Resource variable preview: Read computed styles when validating image variables, keeping the settings preview working with stylesheet-published variables.

🚀 新增

  • 内置背景图片:将已启用的本地图片变量直接应用到 Obsidian 画布,支持随机选择、不透明度、混合模式、尺寸、位置、重复方式和附着方式设置。
  • 背景滤镜:在新的「外观」子页面中使用 CSS 滤镜调整背景图片图层——亮度、对比度、饱和度、灰度、褐色、反色、色相旋转和模糊。

⚡ 变更

  • 基于 Obsidian 1.13 的声明式设置:设置页改用 Obsidian 1.13.0 引入的声明式设置 API,最低所需 Obsidian 版本提升至 1.13.0。背景显示选项(不透明度、混合模式、尺寸、位置、重复方式、附着方式)与滤镜一同归入「背景图片」下的「外观」子页面。

🐛 修复

  • 资源变量发布:将库内资源变量发布到专用样式表中,使其可被计算样式读取,同时避免修改 html 元素的内联样式。
  • 资源变量预览:校验图片变量时读取计算样式,确保变量改用样式表发布后设置页预览仍能正常工作。

README file from

Github

Style Context - Obsidian CSS variable helper

English | 中文文档

Obsidian Download Total Downloads GitHub Issues GitHub Last Commit

An Obsidian plugin that publishes runtime context as CSS classes and variables. It turns things like your current theme and vault image paths into predictable hooks for your own custom CSS snippets, and can optionally apply a vault image variable as a canvas background.

demo

The theme and note-path modules only publish context/state. The optional background image module is a built-in convenience layer; all of its visual options remain configurable in the plugin settings.

What problems does it solve?

Two practical use cases:

  1. Map vault images to stable CSS variables, so you can use local images in background-image and related properties.

[!note]
Why this matters:
in Obsidian, vault resource URLs are regenerated and can change across reloads, which makes direct url() usage unreliable. This plugin gives you stable variable references instead.

  1. Add CSS that only applies to a specific theme, so you can patch/tune theme details without editing the theme's original CSS.

[!note]
Why this matters:
many themes look great overall, but still have details you may want to tweak. If the theme does not expose Style Settings options, targeted CSS overrides are often the safest approach. Editing theme files directly is fragile because updates can overwrite your changes.

How it works

Local image variable

Obsidian regenerates resource URLs on vault reload, so raw paths are not stable inside url(). This module maps a vault image to a stable CSS variable that you can reference from background-image and similar properties.

Image variable

Pick an image in settings, assign a CSS variable name, and then use var(--name) directly in your CSS.

Click the preview image on the left to quickly copy the variable reference:
Copy image variable

ehe
No more uploading images to the web or pasting long base64 strings just to style a background.

💡 here is a sample snippet that uses the image variable to set image background and top logo for file explorer.

Built-in background image

The Background image settings group accepts a complete CSS image value. Paste a local variable reference such as var(--image-1), use a web image such as url("https://example.com/image.jpg"), or click the shuffle button to choose one of your enabled local image variables at random. Remote URLs contact the image host and may disclose normal network request information.

The image layer has its own opacity and blend mode, so it does not make notes or controls translucent. The Appearance sub-page places CSS filters together and keeps size, position, and repeat in a final Layout group. Every slider includes a reset button. Disable the toggle to remove the injected layer and restore the theme's original canvas styles.

Theme context

If a theme supports Style Settings, great, use that first. If it does not, this module gives you a reliable fallback.

When enabled, the plugin adds a theme-specific class to the top-level Obsidian DOM. For example, with the Brutal Gum theme, you get theme-mod-brutal-gum.

Then you can write scoped overrides like:

.theme-mod-brutal-gum .markdown-preview-view {
  /* theme-specific overrides */
  --my-background-color: #66ccff;
  background-color: var(--my-background-color);
}

No setup required for the core behavior, just enable the plugin. You can click to copy the current theme class in settings: Theme class

There is also a command to copy the current theme class, handy when writing CSS snippets.

Batch note CSS classes

This is a bonus feature. If you frequently use the note cssclasses property, this can save time.

You can configure folder path prefixes (or keywords), and matched notes are automatically assigned your chosen CSS class name. That lets you apply styles to whole groups of notes without manually adding cssclasses in each note.

Path mapping settings

Vibe coding level

People often ask, so here is the direct answer: the vibe coding level of this plugin is around 80%.

The plugin itself is actually very small, and started from a personal CST script. The real feature code is lightweight; most of the plugin size comes from settings UI and surrounding structure.

The goal is simple: solve my own daily workflow first, then share it for others who might need the same thing.

Because I use this plugin heavily every day, I am also the first person affected by any issue, which is why I keep maintaining it.

Build

Small convenience trick: if you place a .env file in the plugin folder (or its parent) with:

VAULT_PATH=C:/path/to/your/ObsidianVault

you can run npm run build:local to build and auto-copy into your vault.

Release

After writing complete notes under ## [Unreleased], run npm run release -- <version>. The command requires a clean, synchronized default branch; it synchronizes all version metadata, promotes the changelog entry, runs checks, commits, creates and atomically pushes the tag, then waits for GitHub Actions to verify the published Release and its three plugin assets. Use npm run release:dry-run -- <version> to validate without changing anything.

If a version was already committed and annotated locally, but has not reached GitHub, use npm run release:resume -- <version>. It validates the local tag's immutable metadata and changelog, runs the full check, fast-forwards the default branch and tag atomically, then performs the same CI and asset verification. Use npm run release:resume:dry-run -- <version> to check this recovery path without changes. This is recovery only; ordinary releases must use release.

Support

Nah, this is a small utility. No sponsorship needed, enjoy it <3

If you like my plugin design, you can check my other plugins here:

Moy's plugins - Obsidian Community

样式上下文

一个面向 Obsidian 的 CSS 变量辅助插件。它会把 Obsidian 的特定上下文(当前主题、库内图片路径)转换为 CSS 类名与变量,也可以把图片变量直接应用为画布背景。

主题和笔记路径模块只负责发布状态;可选的背景图片模块提供了内置的便捷样式层,所有视觉选项都可以在插件设置中调整。

它解决什么问题?

举个例子,两大最实用的功能:

  1. 将仓库内的图像映射为稳定的 CSS 变量,便于在 background-image 等属性中引用。

[!note] 为什么有这种需求?
obsidian 的 CSS 中如果想使用图片素材,只能用 url() 来引用网络链接,因为仓库内的图像 URL 每次都会变化。有了这个插件,你就可以直接用仓库内的图片设置背景图了。

  1. 针对某个特定主题添加样式,用来修正/调整那些主题本身没提供的样式,同时不用修改主题本身的 CSS 文件。

[!note] 为什么有这种需求?
很多主题可能本身很好看,但又有一些你想自己调节的地方。如果主题没提供 StyleSettings 设置,就只能自己写 CSS 覆盖,这时候,「只在特定主题生效的 CSS」就很关键。 为什么不直接改主题?因为主题本身一旦更新,你做的改动就会丢失,所以补丁式的 CSS 才是最稳妥的做法。

如何作用?

本地图像变量

Obsidian 每次重载仓库时都会重新生成资源 URL,因此原始路径无法直接稳定地用于 url()。此模块会把仓库内图像映射为稳定的 CSS 变量,便于在 background-image 等属性中引用。

Image variable

只需要在设置中选择图片文件,分配给它的 CSS 变量名——Viola!你就可以在 CSS 中直接使用 var(--name) 来引用它了。

点击左侧的预览图片可以快速复制该图片变量:
alt text

ehe
再也不用想着先把图片传到往上,或者插入冗长的 base64 编码了

💡 点我查看 示例 CSS 样式代码片段,用于给文件资源管理器设置背景图和顶部 LOGO。

内置背景图片

设置中的「背景图片」接受完整的 CSS 图片值。可以直接粘贴 var(--image-1) 这样的本地变量引用,也可以填写 url("https://example.com/image.jpg") 使用网页图片,或点击输入框旁的随机按钮选择已启用的本地图片变量。远程 URL 会连接图片所在网站,并可能暴露常规网络请求信息。

背景图层拥有独立的不透明度和混合模式,不会让笔记或控件一起变透明;「外观」子页面集中排列 CSS 滤镜,并将尺寸、位置和重复方式归入末尾的「布局」组。所有滑块均提供重置按钮。关闭开关即可移除内置图层,恢复主题原本的画布样式。

主题上下文

如果主题提供了StyleSettings设置,那么当然优先使用 StyleSettings。 但是如果主题没有提供——这就需要自己动手了。

我这两年尝试了百来个主题,其中很多都非常喜欢,但又想要自己微调一下。 所以,我写了个脚本(也是这个插件的前身),可以在 Obsidian DOM 的顶部层级加上当前主题对应的类名。

例如,使用 Brutal Gum 主题时,DOM 顶层会加上 theme-mod-brutal-gum 类名。

然后我们就可以用这样的代码去覆盖主题的样式:

.theme-mod-brutal-gum .markdown-preview-view {
  /* 主题专属覆盖样式 */
  --my-background-color: #66ccff;
  background-color: var(--my-background-color);
}

这个不需要设置,启用即可自动生效。

你可以点击并复制当前主题的类名: alt text

此外,插件也提供了 Command 来复制当前主题的类名,方便你在 CSS 片段中使用。

笔记批量分配 CSS 类名

这算个 Bonus 功能—— 如果你经常使用笔记的 cssclasses 属性,它或许会有用。

你可以在设置中填写文件夹路径(或者关键字),匹配的笔记会被自动分配你填写的 CSS 类名。 这样你就可以批量对某类笔记应用特定的 CSS 样式,而不需要在每篇笔记中都手动添加 cssclasses 属性了。

路径映射设置

Vibe Coding 含量

我知道很多人会关心这个,所以直接了当地说:
该插件的 Vibe 浓度大约为 80%

这个插件的体量其实相当小,它来自我之前自己手写的 CST 脚本文件。 因为只是注册几个插件变量的事儿,当时几十行代码就能完事儿。
转成插件之后,我觉得反而是设置部分的代码占了大多数……实际的功能其实就那么点儿,你可以自行检查。

我 Vibe 出来的需求首先是满足我自己的需求,然后才是分享给可能有类似需求的其他用户使用,希望对你有所帮助。

请放心,这个插件是我自己的每日高需求使用插件,因此我是第一责任人,也有着持续维护的必要。

构建

我的插件有一个小技巧:只要你在插件文件夹(或者上层文件夹)放一个 .env 文件,里面写上:

VAULT_PATH=C:/path/to/your/ObsidianVault

那么你就可以直接使用 npm run build:local 来构建并自动拷贝到你的仓库内 ;)

发布

## [Unreleased] 下写完完整更新说明后,运行 npm run release -- 0.3.0。该命令要求默认分支干净且已和远端同步;它会同步所有版本元数据、将 Changelog 条目提升为正式版本、执行检查、提交、创建并原子推送 tag,最后等待 GitHub Actions 验证正式 Release 与三个插件资产。使用 npm run release:dry-run -- 0.3.0 可只做校验,不修改任何内容。

若版本已在本地提交并创建注释 tag,但尚未到达 GitHub,使用 npm run release:resume -- 0.3.0。它会校验本地 tag 中不可变的版本元数据与更新日志、执行完整检查,再原子插入默认分支并推送 tag,之后执行同样的 CI 和资产验证。可用 npm run release:resume:dry-run -- 0.3.0 不改动任何内容地校验此恢复路径。这只用于恢复中断的发布;正常发应始终使用 release

赞助

Nah,我不觉得这种小工具有什么值得赞助的,用得愉快! <3

如果你认可我的插件设计,可以查看我的其他插件:

Moy's plugins - Obsidian Community