MDToSM
approvedby lpp188408
将笔记排版并发布到微信公众号草稿箱,支持贴图导出。 - This plugin has not been manually reviewed by Obsidian staff.
MDToSM
English
MDToSM is a desktop-only Obsidian plugin for formatting Markdown notes and publishing them to WeChat Official Accounts. It provides a compact right-side workspace for previewing, styling, exporting, and submitting articles and image cards.
The plugin converts Markdown notes into WeChat-compatible HTML, preserves local images, supports local cover cropping, and creates drafts through the official WeChat API. Users can choose from multiple article layouts, color themes, mobile and desktop previews, long-image export modes, and image-card drafts with optional text descriptions.
MDToSM is designed for personal desktop use. AppSecret values are stored in the macOS Keychain. The plugin reads the active note through the Obsidian Vault API, does not send note content to an external rendering service, and does not execute user-provided shell commands. The only system command used is the fixed macOS /usr/bin/security tool with fixed arguments for Keychain access.
To install the plugin manually, download main.js, manifest.json, and styles.css from a matching GitHub Release and copy them to <vault>/<config-dir>/plugins/ob-article-to-sm/. Then enable MDToSM in Obsidian's Community plugins settings. See the Chinese documentation below for configuration and usage details.
Install the three files from the matching GitHub Release (main.js, manifest.json, and styles.css) into <vault>/<config-dir>/plugins/ob-article-to-sm/, then enable MDToSM in Obsidian's Community plugins settings. The plugin stores AppSecret values in the macOS Keychain by invoking the fixed system tool /usr/bin/security with fixed command arguments; it does not run user-provided shell commands or write secrets to plugin data files.
中文说明
MDToSM 是用于微信公众号排版、草稿发布和贴图导出的 Obsidian 第三方插件。打开右侧紧凑工作台后,可预览当前笔记、切换主题、选择公众号账号、创建草稿或直接提交发布,也可把笔记生成贴图并保存到 Vault 或公众号草稿箱。
功能
- 右侧紧凑工作台:
Cmd + P → 打开公众号发布工作台;未配置账号也可以刷新完整文章预览 - 多公众号:设置页按
名称|AppID|AppSecret每行配置一个账号,AppSecret 使用 macOS 钥匙串加密保存 - 六套颜色主题:简约黑白、科技蓝、商务绿、人文墨、杂志红、暖橙生活
- 五种排版选择:不套用模板、杂志叙事、现代商务、阅读手记、技术蓝图
- 排版模板与颜色主题可自由组合,并记住最后一次选择
- Markdown 转公众号友好 HTML,标题、引用、列表、表格、图片和代码均使用公众号兼容的内联样式
- Obsidian 本地图片
![[image.png|120x80]]自动转换;保存草稿时上传到微信并替换为微信 CDN 地址 - 从笔记 frontmatter 读取标题、作者、摘要及评论设置,并兼容旧版 frontmatter 封面
- 侧栏可选择电脑本地封面,不修改笔记内容;发布时自动上传为公众号永久素材
- AppSecret 仅保存在 macOS 系统钥匙串中,插件不会写入日志
- 工作台提供“公众号 / 贴图”标签,每次打开插件默认回到公众号,贴图排版设置会长期保存
- 贴图支持单张长图、智能多页切片和 Markdown 分割线切片,提供六种比例及自定义尺寸
- 贴图支持字体、字号、纯色或渐变背景、页面留白和圆角,按
2x倍率生成 PNG - 贴图可导出到
贴图导出/<文章名>/,也可创建纯图片或图片加文字描述的公众号贴图草稿
安装
npm install
npm run build
mkdir -p "<vault>/<config-dir>/plugins/ob-article-to-sm"
cp main.js manifest.json styles.css "<vault>/<config-dir>/plugins/ob-article-to-sm/"
然后在 Obsidian 的“设置 → 第三方插件”中启用 MDToSM。
从旧版迁移
从 md-to-sm、obsidian-to-sm 或 wechat-article-studio 升级时,首次启用新版会自动迁移账号配置和本地封面到 .obsidian/plugins/ob-article-to-sm/。迁移成功后可在“设置 → 第三方插件”中停用旧版插件。
笔记格式
frontmatter 可省略;未填写时,标题默认取笔记的第一个 H1 或文件名,作者取插件设置。
---
标题: 我的公众号文章
作者: 张三
摘要: 这是一段用于公众号展示的摘要。
打开评论: true
仅粉丝可评论: false
---
# 我的公众号文章
正文中的本地图片:![[diagram.png|800]]
也支持对应英文键:title、author、digest、cover、need_open_comment、only_fans_can_comment。
公众号配置
在插件设置中填写 AppID 和 AppSecret。公众号后台还必须满足:
- 账号具备获取
access_token、上传素材和创建草稿的 API 权限。 - 将运行 Obsidian 的机器公网 IP 加入公众号后台 IP 白名单。
- 在右侧工作台为笔记选择电脑本地封面;或者在插件设置中填已有的永久素材
thumb_media_id。
如果未满足 IP 白名单或 API 权限,插件会显示微信返回的错误,草稿不会创建。
使用
右侧发布工作台
- 打开目标笔记。
- 执行命令
打开公众号发布工作台。 - 顶部采用左右布局:左侧上方显示封面、下方显示五个操作菜单;右侧依次显示公众号、颜色主题、排版模板和手机/PC 预览切换。左右两列及最后一行保持对齐,封面图片独立保存在插件目录中,不写入笔记。
- 完整文章预览位于顶部设置区下方并使用工作台全宽。
- 手机预览将正文限制为约 375 像素并居中,PC 预览使用右侧可用宽度;插件会记住最后一次选择。
- 排版模板与颜色主题可自由组合,切换后立即刷新预览。预览、刷新、复制和样式切换不需要账号。
- “创建草稿”只保存到草稿箱;“直接发布”创建草稿后提交微信发布任务,并轮询确认发布结果。微信仍在处理时以公众号后台最终状态为准。
预览与复制
执行 复制当前笔记到公众号,在预览窗口检查样式后点击“复制到公众号”,将富文本粘贴到公众号编辑器。
贴图模式
- 在右侧工作台顶部切换到“贴图”,打开的当前笔记会自动进入贴图预览。
- 工具栏依次提供纯图片草稿、图片加描述草稿、导出到 Vault、复制文案、刷新和贴图设置。
- 设置按钮在侧栏内部打开抽屉,可选择单张长图、多页切片或分割线切片,并调整比例、尺寸、字体、背景、留白和圆角。
- 单张长图超过
16000px时插件会停止生成,并提示切换到多页模式;公众号贴图草稿最多支持 20 张图片。 - 两种公众号贴图操作都只创建草稿,不会直接正式发表。第一张生成图片自动作为贴图封面,无需另选文章封面。
分割线切片会优先按 Markdown 的 --- 分页;单段内容仍然过长时,会继续按正文块边界智能切分。导出时不会覆盖旧文件,同名文章会自动增加批次序号。
验证
npm run build
npm test
手动验证:安装插件后,用包含标题、代码和本地正文图的笔记选择本地封面并执行一键保存。成功时公众号草稿箱会出现文章;重点检查标题、摘要、封面、正文图片和代码块。
贴图验证:切换手机画框、单图、多图和分割线模式,确认表格、代码、本地图片与 PNG 一致,并检查 Vault 中导出的图片可以正常打开。
发布社区版
维护者发布新版本时,先更新 manifest.json、package.json 和 versions.json 的版本号,执行 npm test 与 npm run build。随后创建与版本号一致的 GitHub Release,并上传 main.js、manifest.json、styles.css 三个附件。首次提交到 Obsidian 社区目录前,请确认仓库公开、README、LICENSE 和 第三方声明 均位于仓库根目录。
边界
- “直接发布”提交的是微信图文发布任务,不等于向全部粉丝群发;是否成功公开以公众号后台状态为准。
- 直发草稿依赖微信公众号 API 权限和 IP 白名单;没有稳定白名单出口时,请使用复制模式或部署固定 IP 的发布代理。
- 微信编辑器会过滤部分 HTML/CSS,最终显示以公众号草稿预览为准。
- 贴图固定使用简洁样式,不继承公众号颜色主题和排版模板。
- 贴图模式不提供小红书跳转、外部背景服务、水印、本地字体扫描或自动降低清晰度。
第三方组件及许可见 第三方声明。
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.