跳到主内容 / Skip to content
Materin

首页Home / 内容Content / Materin Ctx

Materin Ctx v0.1.1

在 Obsidian 中直接打开、查看、编辑 JSON / YAML 文件 —— 原生手感的 CodeMirror 6 编辑器视图,支持格式化、折叠与搜索。

Open, view and edit JSON / YAML files inside Obsidian — a native-feeling CodeMirror 6 editor view with formatting, folding and search.

与系列共用同一套 UI 规范:Materin UIShares one UI spec with the series: Materin UI

概览

点击 vault 里的 .json / .yaml / .yml / .jsonc 文件,Materin Ctx 会在 Obsidian 内以编辑器视图打开它,而不是弹出系统应用。高亮、折叠、搜索、格式化、保存一应俱全,且格式化会保留注释。

功能

  • 文件接管 —— 点击 vault 中的 JSON / YAML 文件,直接在 Obsidian 内打开,不再弹出系统应用;
  • 语法高亮 + 行号 —— 基于 CodeMirror 6(Obsidian 内置运行时),与原生编辑器手感一致;
  • 折叠 —— 点击行号槽的箭头折叠对象 / 数组 / YAML 块;支持「全部折叠 / 全部展开」按钮与命令;
  • 搜索 —— Ctrl/Cmd + F 打开搜索面板,支持高亮全部、大小写、正则与替换;
  • 格式化 —— 一键按配置重新缩进:JSON / JSONC 容错重缩进(语法有错也能排版)并保留注释;YAML 走 Document 往返、保留注释,支持行宽限制(0 = 不限制);
  • 编辑与保存 —— 直接编辑,Ctrl/Cmd + S 或「保存」按钮写回文件;未保存改动以橙色圆点提示;
  • 外部修改同步 —— 文件在磁盘上被其他工具修改后自动刷新;若有未保存改动,显示提示条由你决定是否重载;
  • 设置 —— 缩进字符(空格 / Tab)、缩进宽度(2 / 4 / 8)、自动换行、行号、打开时折叠、YAML 行宽。

备注

  • YAML 规范禁止 Tab 缩进:设置选择 Tab 时,YAML 格式化自动回退为对应宽度的空格(编辑器缩进仍使用 Tab);
  • 读取文件时会剥离 BOM,保存时不回写;
  • 文件行尾(CRLF / LF)在保存时保持原样;
  • JSONC:语法高亮按 JSON 处理(注释无高亮),校验与格式化按 JSONC 宽松规则(允许尾随逗号、注释)。

安装

  1. 从 Release 页下载 main.js、manifest.json、styles.css;
  2. 放入 <vault>/.obsidian/plugins/materin-ctx/;
  3. 启用插件即可。

开发

npm install        # 安装依赖
npm run dev        # 开发构建(watch,自动部署到 .debug-vault)
npm test           # vitest 单元测试
npm run check      # tsc 类型检查
npm run lint       # eslint(eslint-plugin-obsidianmd recommended)
npm run build      # 生产构建(root main.js)

调试 vault 位于 .debug-vault/(含热重载插件),npm run dev 后用 Obsidian 打开该 vault 即可热重载调试。示例文件:sample.json / config.yaml / settings.jsonc。

许可

MIT。

内容来源

本页同步自仓库 README(leapord/Materin-ctx,最后提交 2026-08-30,版本 0.1.1)。以源码仓库为准。

Overview

Click a .json / .yaml / .yml / .jsonc file in your vault and Materin Ctx opens it in an editor view inside Obsidian instead of handing it off to a system app. Highlighting, folding, search, formatting and saving are all there — and formatting preserves comments.

Features

  • Takes over the files — clicking JSON / YAML files in the vault opens them inside Obsidian, no system app popup;
  • Syntax highlighting + line numbers — based on CodeMirror 6 (Obsidian's built-in runtime), matching the native editor feel;
  • Folding — click the arrow in the gutter to fold objects / arrays / YAML blocks; "fold all / unfold all" buttons and commands included;
  • Search — Ctrl/Cmd + F opens the search panel with highlight-all, case sensitivity, regex and replace;
  • Formatting — re-indent according to settings in one action: JSON / JSONC is re-indented fault-tolerantly (it still formats when the syntax is broken) and keeps comments; YAML goes through a Document round-trip, keeps comments, and supports a line-width limit (0 = unlimited);
  • Editing and saving — edit directly, write back with Ctrl/Cmd + S or the save button; unsaved changes are flagged with an orange dot;
  • External change sync — if another tool modifies the file on disk it refreshes automatically; with unsaved changes a prompt lets you decide whether to reload;
  • Settings — indent character (spaces / tab), indent width (2 / 4 / 8), word wrap, line numbers, fold on open, YAML line width.

Notes

  • The YAML spec forbids tab indentation: when tabs are selected, YAML formatting falls back to spaces of the corresponding width (the editor still indents with tabs);
  • A BOM is stripped when reading and not written back on save;
  • Line endings (CRLF / LF) are preserved on save;
  • JSONC: syntax highlighting is treated as JSON (comments are not highlighted) while validation and formatting follow lenient JSONC rules (trailing commas and comments allowed).

Install

  1. Download main.js, manifest.json and styles.css from the releases page;
  2. Put them into <vault>/.obsidian/plugins/materin-ctx/;
  3. Enable the plugin.

Development

npm install        # install dependencies
npm run dev        # dev build (watch, auto-deploys to .debug-vault)
npm test           # vitest unit tests
npm run check      # tsc type check
npm run lint       # eslint (eslint-plugin-obsidianmd recommended)
npm run build      # production build (root main.js)

The debug vault lives in .debug-vault/ (with a hot-reload plugin): run npm run dev, open that vault in Obsidian and changes hot-reload. Sample files: sample.json / config.yaml / settings.jsonc.

License

MIT.

Source

This page is synced from the repository README (leapord/Materin-ctx, last commit 2026-08-30, version 0.1.1). The source repository is authoritative.