README file from
GithubCanvas from Headings
将 Obsidian 笔记中的标题(H1 / H2 / H3...)自动转换为画布(Canvas)节点的插件。适用于人物关系梳理、故事结构可视化、知识图谱构建等场景。
本插件已完成架构重构,新增多视图面板、视图联动、可视化设置面板等能力,后续将持续扩展更多创作辅助模块。
中文
✨ 功能一览
| 功能模块 | 说明 |
|---|---|
| 一键生成画布 | 从当前 Markdown 笔记的 H1/H2 标题自动生成 Canvas 文件,无需手动拖拽节点。 |
| 智能关系识别 | 自动解析 ### 关系 段落中的 [[双向链接]] 与 **粗体标签**,生成带标签和颜色的关系线。 |
| 亲属关系自动布局 | 识别主角(【主角】标记或首个 H1 节点),按辈分(长辈/同辈/晚辈)和性别自动排布节点位置。 |
| 分组自动生成 | 根据关系标签和 H1 分组,自动在画布上生成彩色分组框,支持一键清除与重建。 |
| 关系线重建 | 支持三种重建模式:完全重建、删除后重建、保留现有关系线补建。 |
| 手动布局模式 | 生成画布后进入手动布局模式,右键画布空白处可随时重建关系线或清除分组。 |
| 标题预览面板 | 独立侧边栏面板,实时显示当前笔记的 H1/H2 结构,与生成器面板联动。 |
| 可视化设置面板 | 在 Obsidian 设置中提供图形化配置页,可调整节点宽度、固定高度、自动打开行为等。 |
📦 安装
| 方式 | 步骤 |
|---|---|
| 社区插件市场(推荐) | 设置 → 第三方插件 → 浏览 → 搜索 "Canvas from Headings" → 安装 → 启用 |
| BRAT | 安装 BRAT → 添加仓库 hotdog-box/canvas-from-headings → 启用 |
| 手动安装 | 下载 main.js、manifest.json、styles.css → 放入 .obsidian/plugins/canvas-from-headings/ → 重启 Obsidian 并启用 |
🚀 快速开始
- 安装插件 → 打开任意包含标题的 Markdown 笔记。
- 触发生成 → 点击左侧 Ribbon 图标,或按
Ctrl/Cmd + P搜索 "生成画布"。 - 调整布局 → 在弹出的弹窗中确认选项(是否删除分组、是否删除连接线、是否使用简略尺寸)。
- 手动微调 → 画布生成后进入手动布局模式,拖动节点调整位置。
- 重建关系线 → 在画布空白处右键,选择 "是否按现有布局建立关系线?"。
🖥️ 面板与视图
插件提供两个独立视图面板,可通过命令面板打开:
| 面板 | 打开命令 | 说明 |
|---|---|---|
| Canvas 生成器 | 打开 Canvas 生成器面板 |
显示当前笔记信息,一键生成画布,支持预览结构。 |
| 标题预览 | 打开标题预览面板 |
实时显示当前笔记的 H1/H2 结构树,与生成器联动。 |
💡 视图联动:在生成器面板中点击 "🔍 预览结构",预览面板会自动打开(或更新内容),无需手动切换。
⌨️ 命令列表
| 命令 | 说明 |
|---|---|
生成画布 |
从当前笔记标题生成 Canvas 文件 |
智能白板:按现有布局建立关系线 |
根据当前画布布局重新生成关系线 |
打开 Canvas 生成器面板 |
打开生成器视图 |
打开标题预览面板 |
打开标题预览视图 |
⚙️ 设置项
在 设置 → 第三方插件 → Canvas from Headings 中配置:
| 设置项 | 默认值 | 说明 |
|---|---|---|
| 生成画布后自动打开 | 开启 | 生成画布后是否立即在 Obsidian 中打开该文件。 |
| 预览面板自动打开 | 开启 | 点击"预览结构"时,如果预览面板未打开,是否自动打开。 |
| 节点默认宽度 | 380 | 画布节点的宽度(像素),推荐 300~500。 |
| 节点固定高度 | 0 | 设为 0 则根据文本内容自动计算高度;设为非 0 值则所有节点使用固定高度(推荐 150~600)。 |
📝 笔记格式建议
为获得最佳效果,建议笔记遵循以下结构:
# 主角组
## 张三【主角】
张三是一个少年。
### 关系
- **挚友** [[李四]]
- **师父** [[王五]]
## 李四
李四的简介。
# 配角组
## 王五
- H1 → 生成画布分组(如"主角组""配角组")。
- H2 → 生成画布文本节点。
### 关系下的[[链接]]→ 生成带标签的关系线。**粗体**→ 作为关系线的标签文字。【主角】→ 标记主角节点,插件会以该节点为中心进行布局。
🧱 架构说明
本插件采用分层架构,源码按职责拆分为以下模块:
src/
├── constants.ts # 界面文字、布局常量
├── types/ # 全局类型定义
├── core/
│ ├── EventBus.ts # 事件总线(视图间通信)
│ ├── PluginState.ts # 全局状态容器
│ ├── Settings.ts # 设置管理器
│ └── events.ts # 事件名常量
├── services/
│ ├── HeadingParser.ts # 标题解析服务
│ ├── LayoutEngine.ts # 布局计算引擎
│ ├── CanvasService.ts # 画布文件读写
│ └── EdgeService.ts # 关系线生成与重建
├── ui/
│ ├── views/ # 自定义视图(ItemView)
│ ├── modals/ # 设置页、弹窗
│ └── components/ # 可复用 UI 片段
└── utils/ # 通用工具
- 服务层(
services/)不依赖 UI,可独立测试。 - 视图层(
ui/views/)通过EventBus通信,互不直接引用。 - 状态层(
core/PluginState.ts)集中管理跨模块共享状态。
🛠️ 开发
# 安装依赖
npm install
# 编译(监听模式)
npm run dev
# 编译(单次)
npm run build
编译产物为项目根目录的 main.js。
📄 许可证
English
✨ Features
| Feature | Description |
|---|---|
| One-Click Canvas | Automatically generates Canvas nodes from H1/H2 headings in the active note. |
| Smart Relationship Parsing | Parses [[wikilinks]] and **bold labels** under ### 关系 sections to create labeled, colored edges. |
| Kinship-Aware Layout | Detects the protagonist (marked with 【主角】 or the first H1 node) and arranges nodes by generation (elder/same/younger) and gender. |
| Auto Group Generation | Creates colored group frames based on relationship labels and H1 sections. Supports one-click clearing and rebuilding. |
| Edge Rebuild Modes | Three rebuild modes: Full Rebuild, Delete & Rebuild, Keep & Add. |
| Manual Layout Mode | After generation, right-click the canvas to rebuild edges or clear groups at any time. |
| Heading Preview Panel | A dedicated sidebar panel that displays the H1/H2 structure of the active note in real time. |
| Visual Settings Panel | Graphical settings page in Obsidian to configure node width, fixed height, auto-open behaviors, and more. |
📦 Installation
| Method | Steps |
|---|---|
| Community Plugin Store (Recommended) | Settings → Community Plugins → Browse → Search "Canvas from Headings" → Install → Enable |
| BRAT | Install BRAT → Add repo hotdog-box/canvas-from-headings → Enable |
| Manual | Download main.js, manifest.json, styles.css → Place in .obsidian/plugins/canvas-from-headings/ → Restart Obsidian and enable |
🚀 Quick Start
- Install the plugin → Open any Markdown note containing headings.
- Trigger generation → Click the Ribbon icon, or press
Ctrl/Cmd + Pand search for "Generate Canvas". - Adjust layout → Confirm options in the modal (delete groups, delete edges, simple size).
- Fine-tune manually → Drag nodes to adjust positions in manual layout mode.
- Rebuild edges → Right-click on the canvas blank area and select "Rebuild edges from current layout?".
🖥️ Panels & Views
The plugin provides two independent view panels, accessible via the Command Palette:
| Panel | Command | Description |
|---|---|---|
| Canvas Generator | Open Canvas Generator Panel |
Shows active note info, one-click generation, and structure preview. |
| Heading Preview | Open Heading Preview Panel |
Displays the H1/H2 structure tree of the active note in real time. |
💡 View Linking: Click "🔍 Preview Structure" in the Generator panel to automatically open (or update) the Preview panel.
⌨️ Commands
| Command | Description |
|---|---|
Generate Canvas |
Creates a Canvas file from the active note's headings |
Smart Board: Rebuild Edges from Current Layout |
Regenerates edges based on the current canvas layout |
Open Canvas Generator Panel |
Opens the Generator view |
Open Heading Preview Panel |
Opens the Preview view |
⚙️ Settings
Configure in Settings → Community Plugins → Canvas from Headings:
| Setting | Default | Description |
|---|---|---|
| Auto-open Canvas | On | Whether to immediately open the generated Canvas file. |
| Auto-open Preview | On | Whether to automatically open the Preview panel when clicking "Preview Structure". |
| Node Default Width | 380 | Width of Canvas nodes in pixels (recommended 300–500). |
| Node Fixed Height | 0 | 0 = auto-calculate height based on content; non-zero = fixed height for all nodes (recommended 150–600). |
📝 Recommended Note Format
For best results, structure your notes as follows:
# Protagonist Group
## Zhang San【Protagonist】
Zhang San is a young boy.
### Relationships
- **Best Friend** [[Li Si]]
- **Master** [[Wang Wu]]
## Li Si
Li Si's profile.
# Supporting Group
## Wang Wu
- H1 → Creates canvas groups (e.g., "Protagonist Group").
- H2 → Creates canvas text nodes.
[[Wikilinks]]under### Relationships→ Creates labeled edges.**Bold text**→ Used as edge labels.【Protagonist】→ Marks the protagonist node for centered layout.
🧱 Architecture
The plugin follows a layered architecture:
src/
├── constants.ts # UI text, layout constants
├── types/ # Global type definitions
├── core/
│ ├── EventBus.ts # Event bus (inter-view communication)
│ ├── PluginState.ts # Global state container
│ ├── Settings.ts # Settings manager
│ └── events.ts # Event name constants
├── services/
│ ├── HeadingParser.ts # Heading parsing service
│ ├── LayoutEngine.ts # Layout computation engine
│ ├── CanvasService.ts # Canvas file I/O
│ └── EdgeService.ts # Edge generation & rebuilding
├── ui/
│ ├── views/ # Custom views (ItemView)
│ ├── modals/ # Settings tab, modals
│ └── components/ # Reusable UI fragments
└── utils/ # General utilities
- Service layer (
services/) is UI-agnostic and independently testable. - View layer (
ui/views/) communicates viaEventBus, no direct cross-references. - State layer (
core/PluginState.ts) manages cross-module shared state.
🛠️ Development
# Install dependencies
npm install
# Build (watch mode)
npm run dev
# Build (single run)
npm run build
Output is written to main.js in the project root.
📄 License
---