Obsidian Execute Code 插件使用教程
项目的目录结构及介绍
Obsidian Execute Code 插件的目录结构相对简单,主要包含以下几个部分:
obsidian-execute-code/
├── main.ts
├── manifest.json
├── styles.css
└── README.md
- main.ts: 这是插件的主文件,包含了插件的核心逻辑。
- manifest.json: 这是插件的清单文件,包含了插件的元数据,如名称、版本、作者等信息。
- styles.css: 这是插件的样式文件,定义了插件的外观和样式。
- README.md: 这是项目的说明文档,包含了插件的介绍、安装方法、使用说明等。
项目的启动文件介绍
插件的启动文件是 main.ts
,它负责初始化插件并注册各种事件处理程序。以下是 main.ts
文件的主要内容:
import { Plugin } from 'obsidian';
import { ExecuteCodeSettings, ExecuteCodeSettingTab, DEFAULT_SETTINGS } from './settings';
export default class ExecuteCodePlugin extends Plugin {
settings: ExecuteCodeSettings;
async onload() {
await this.loadSettings();
this.addCommand({
id: 'execute-code-block',
name: 'Execute Code Block',
callback: () => {
this.executeCodeBlock();
}
});
this.addSettingTab(new ExecuteCodeSettingTab(this.app, this));
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
executeCodeBlock() {
// 执行代码块的逻辑
}
}
- onload(): 插件加载时调用的方法,负责注册命令和设置选项卡。
- loadSettings(): 加载插件的配置。
- saveSettings(): 保存插件的配置。
- executeCodeBlock(): 执行代码块的逻辑。
项目的配置文件介绍
插件的配置文件是 manifest.json
,它包含了插件的基本信息和依赖项。以下是 manifest.json
文件的内容:
{
"id": "execute-code",
"name": "Execute Code",
"version": "1.0.0",
"minAppVersion": "0.12.0",
"description": "This plugin allows you to execute code blocks in your notes.",
"author": "twibiral",
"authorUrl": "https://github.com/twibiral",
"isDesktopOnly": false
}
- id: 插件的唯一标识符。
- name: 插件的名称。
- version: 插件的版本号。
- minAppVersion: 插件支持的最低 Obsidian 版本。
- description: 插件的描述。
- author: 插件的作者。
- authorUrl: 作者的网址。
- isDesktopOnly: 是否仅支持桌面版 Obsidian。
以上是 Obsidian Execute Code 插件的基本介绍和使用教程,希望对你有所帮助。