# OpsToMP - Obsidian笔记转微信公众号工具 / Obsidian to WeChat Official Account Tool 一个功能完整的Obsidian插件,用于将Markdown笔记转换并发布到微信公众号。 A comprehensive Obsidian plugin for converting and publishing Markdown notes to WeChat Official Accounts. --- ## 项目简介 / Project Introduction OpsToMP是一个专为Obsidian设计的插件,提供完整的解决方案,帮助用户将Obsidian中的Markdown笔记转换并发布到微信公众号。 OpsToMP is an Obsidian plugin that provides a complete solution to help users convert and publish Markdown notes from Obsidian to WeChat Official Accounts. - **Obsidian插件**:集成在Obsidian中的插件,提供图形化界面和实时预览 - **Obsidian Plugin**: Integrated plugin in Obsidian with graphical interface and real-time preview --- ## 功能特性 / Features ### Obsidian插件功能 / Obsidian Plugin Features - 📝 **Markdown转HTML**:将Markdown格式转换为微信公众号支持的HTML格式 - 👁️ **实时预览**:在Obsidian中预览微信公众号格式的渲染效果 - 📤 **上传草稿箱**:一键上传到微信公众号草稿箱 - 🚀 **直接发布**:支持直接发布到微信公众号 - 🖼️ **图片支持**:自动上传本地图片到微信服务器,支持`file:///` URL和Obsidian内部链接 - 🎨 **样式美化**:自动应用微信公众号风格的样式,支持多种主题 - 🔒 **安全防护**:内置XSS防护,过滤危险标签和属性 - 🌐 **网络测试**:测试网络连接和API密钥有效性 - ✨ **一键排版**:支持多种排版选项,包括段落间距、标题格式、图片优化、引用样式、代码块美化、列表格式优化、取消多余换行 - 📋 **内容管理**:查看和管理草稿箱、已发布文章列表 - 🗑️ **删除功能**:删除草稿或已发布文章 - 📝 **Markdown to HTML**: Convert Markdown format to WeChat Official Account compatible HTML - 👁️ **Real-time Preview**: Preview WeChat Official Account rendering effects in Obsidian - 📤 **Upload to Drafts**: One-click upload to WeChat Official Account drafts - 🚀 **Direct Publishing**: Support direct publishing to WeChat Official Account - 🖼️ **Image Support**: Automatically upload local images to WeChat server, supporting `file:///` URLs and Obsidian internal links - 🎨 **Style Beautification**: Automatically apply WeChat Official Account style with multiple themes support - 🔒 **Security Protection**: Built-in XSS protection, filtering dangerous tags and attributes - 🌐 **Network Testing**: Test network connection and API key validity - ✨ **One-Click Formatting**: Support multiple formatting options including paragraph spacing, heading unification, image optimization, quote styling, code block beautification, list formatting, and removing extra line breaks - 📋 **Content Management**: View and manage drafts and published articles lists - 🗑️ **Delete Function**: Delete drafts or published articles --- ## 项目结构 / Project Structure ``` OpsToMP/ ├── plugin-build/ # Obsidian插件构建目录 / Obsidian plugin build directory │ ├── src/ # 源代码 / Source code │ │ ├── api.js # 微信公众号API封装 / WeChat Official Account API wrapper │ │ ├── main.js # 插件主文件 / Plugin main file │ │ ├── settings.js # 设置页面 / Settings page │ │ ├── sidebar.js # 侧边栏视图 / Sidebar view │ │ ├── styles.css # 样式文件 / Styles file │ │ └── utils.js # 工具函数 / Utility functions │ ├── build/ # 构建输出 / Build output (用于发布 / For release) │ │ ├── main.js # 编译后的插件 / Compiled plugin │ │ ├── manifest.json # 插件清单 / Plugin manifest │ │ └── styles.css # 样式文件 / Styles file │ ├── esbuild.config.mjs # esbuild配置文件 / esbuild configuration │ ├── package.json # 项目依赖配置 / Project dependencies │ └── package-lock.json # 依赖锁定文件 / Dependencies lock file ├── README.md # 项目说明文档 / Project documentation (中文) ├── README_EN.md # 英文说明文档 / Project documentation (English) ├── LICENSE # 许可证文件 / License file └── .gitignore # Git忽略文件 / Git ignore file ``` --- ## 快速开始 / Quick Start ### Obsidian插件安装 / Obsidian Plugin Installation #### 方法1:手动安装 / Method 1: Manual Installation 1. 下载最新版本的插件文件 / Download the latest plugin files 2. 将文件复制到Obsidian的插件目录 / Copy files to Obsidian plugins directory: - Windows: `%APPDATA%\Obsidian\plugins\opsto-mp\` - macOS: `~/Library/Application Support/Obsidian/Plugins/opsto-mp/` - Linux: `~/.config/obsidian/plugins/opsto-mp/` 3. 在Obsidian中启用插件:设置 → 社区插件 → OpsToMP → 启用 / Enable plugin in Obsidian: Settings → Community Plugins → OpsToMP → Enable #### 方法2:从源码构建 / Method 2: Build from Source ```bash # 进入插件构建目录 / Enter plugin build directory cd plugin-build # 安装依赖 / Install dependencies npm install # 构建插件 / Build plugin npm run build # 将build目录下的文件复制到Obsidian插件目录 / Copy files from build directory to Obsidian plugins directory ``` --- ## 配置说明 / Configuration ### 获取微信公众号凭证 / Get WeChat Official Account Credentials 1. 登录[微信公众平台](https://mp.weixin.qq.com/) / Login to [WeChat Official Account Platform](https://mp.weixin.qq.com/) 2. 进入"开发" → "基本配置" / Go to "Development" → "Basic Configuration" 3. 获取AppID和AppSecret / Get AppID and AppSecret ### Obsidian插件配置 / Obsidian Plugin Configuration 1. 打开Obsidian设置 / Open Obsidian Settings 2. 找到"OpsToMP"插件设置 / Find "OpsToMP" plugin settings 3. 填写以下信息 / Fill in the following information: - **AppID**:微信公众号的AppID / WeChat Official Account AppID - **AppSecret**:微信公众号的AppSecret / WeChat Official Account AppSecret - **网络测试URL**:默认为百度,可自定义 / Network test URL, default is Baidu, customizable - **超时时间**:网络请求超时时间(毫秒)/ Network request timeout (milliseconds) - **默认主题**:选择默认的微信公众号样式主题 / Select default WeChat Official Account style theme --- ## 使用方法 / Usage ### Obsidian插件使用 / Obsidian Plugin Usage #### 打开发布面板 / Open Publishing Panel - 点击左侧工具栏的微信图标 / Click the WeChat icon in the left toolbar - 或使用命令面板:`打开微信公众号发布面板` / Or use command palette: `Open WeChat Official Account Publishing Panel` #### 预览文档 / Preview Document 1. 在Obsidian中打开要预览的笔记 / Open the note you want to preview in Obsidian 2. 点击侧边栏中的"预览当前文档"按钮 / Click "Preview Current Document" button in the sidebar 3. 查看微信公众号格式的预览效果 / View the preview in WeChat Official Account format #### 上传到草稿箱 / Upload to Drafts 1. 在Obsidian中打开要上传的笔记 / Open the note you want to upload in Obsidian 2. 点击侧边栏中的"上传到草稿箱"按钮 / Click "Upload to Drafts" button in the sidebar 3. 等待上传完成 / Wait for upload to complete 4. 在微信公众号后台查看草稿 / View drafts in WeChat Official Account backend #### 发布到公众号 / Publish to Official Account 1. 在Obsidian中打开要发布的笔记 / Open the note you want to publish in Obsidian 2. 点击侧边栏中的"发布到公众号"按钮 / Click "Publish to Official Account" button in the sidebar 3. 等待发布完成 / Wait for publishing to complete 4. 在微信公众号后台查看已发布的文章 / View published articles in WeChat Official Account backend #### 设置封面图片 / Set Cover Image 在上传或发布时,可以选择设置封面图片 / When uploading or publishing, you can set a cover image: - 支持本地图片文件 / Support local image files - 支持网络图片URL / Support network image URLs #### 网络测试 / Network Testing - 点击"测试网络连接"按钮测试网络连通性 / Click "Test Network Connection" button to test network connectivity - 点击"测试API密钥"按钮验证微信公众号凭证 / Click "Test API Keys" button to verify WeChat Official Account credentials #### 一键排版 / One-Click Formatting 1. 勾选"启用一键排版"复选框 / Check "Enable One-Click Formatting" checkbox 2. 根据需要选择排版选项 / Select formatting options as needed: - **自动添加段落间距**:统一段落间距 / Auto paragraph spacing: Unify paragraph spacing - **统一标题格式**:标准化各级标题样式 / Unify headings: Standardize heading styles - **优化图片显示**:图片居中、圆角、阴影 / Optimize images: Center images, add rounded corners and shadows - **添加引用样式**:美化引用块 / Quote styling: Beautify quote blocks - **代码块美化**:美化代码块和行内代码 / Code block beautification: Beautify code blocks and inline code - **列表格式优化**:统一列表缩进和间距 / List formatting: Unify list indentation and spacing - **取消多余换行**:移除多余的空行,段落间最多空一行 / Remove extra breaks: Remove extra blank lines, max one blank line between paragraphs 3. 点击"预览当前文档"或"上传至草稿箱"查看效果 / Click "Preview Current Document" or "Upload to Drafts" to see the effect #### 内容管理 / Content Management ##### 查看草稿列表 / View Draft List 1. 点击侧边栏中的"查看草稿列表"按钮 / Click "View Draft List" button in the sidebar 2. 查看所有草稿及其状态 / View all drafts and their status 3. 点击草稿卡片查看详情 / Click draft card to view details 4. 点击"删除"按钮删除草稿 / Click "Delete" button to delete draft ##### 查看已发布文章 / View Published Articles 1. 点击侧边栏中的"查看已发布文章"按钮 / Click "View Published Articles" button in the sidebar 2. 查看所有已发布文章及其状态 / View all published articles and their status 3. 点击文章卡片查看详情 / Click article card to view details 4. 点击"删除"按钮删除已发布文章 / Click "Delete" button to delete published article **注意**:内容管理功能需要公众号完成个人认证。如果出现权限错误,请前往微信公众平台完成认证。/ **Note**: Content management features require WeChat Official Account personal authentication. If permission errors occur, please complete authentication on the WeChat Official Account Platform. --- ## Markdown支持 / Markdown Support 插件和Python工具都支持以下Markdown语法 / Both plugin and Python tools support the following Markdown syntax: - 标题(`#`、`##`、`###`等)/ Headers (`#`, `##`, `###`, etc.) - 代码块(``` ```)/ Code blocks (``` ```) - 加粗(`**text**`)/ Bold (`**text**`) - 斜体(`*text*`)/ Italic (`*text*`) - 链接(`[text](url)`)/ Links (`[text](url)`) - 图片(`![alt](url)`)/ Images (`![alt](url)`) - Obsidian内部链接(`![[图片名.png]]`)/ Obsidian internal links (`![[image.png]]`) - 引用(`> text`)/ Blockquotes (`> text`) - 列表(有序和无序)/ Lists (ordered and unordered) --- ## 技术实现 / Technical Implementation ### Obsidian插件技术栈 / Obsidian Plugin Tech Stack - **框架**:Obsidian Plugin API / **Framework**: Obsidian Plugin API - **打包工具**:esbuild / **Build Tool**: esbuild - **HTTP客户端**:axios / **HTTP Client**: axios - **表单处理**:form-data / **Form Processing**: form-data - **Node.js版本**:>= 16 / **Node.js Version**: >= 16 ### 安全特性 / Security Features #### XSS防护 / XSS Protection - 过滤危险标签(`