Convert Markdown articles into a format acceptable to the Zhihu article editor, support previews in multiple layout styles, and publish to Zhihu Columns with one click.
Quick Start
Dependency Installation
# 格式转换依赖
pip install markdown pygments beautifulsoup4
# 一键发布依赖(可选,仅发布时需要)
pip install playwright requests
playwright install chromium
Format Conversion (Single Article)
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py input.md
Parameter Description:
| Parameter | Description | Default |
|---|---|---|
input.md |
Path to the input Markdown file | Required |
-o output.html |
Path to the output HTML file | {input}_zhihu.html |
--theme |
Theme Style | zhihu |
--content-only |
Output only pure HTML content (for API publishing) | No |
--dir |
Batch conversion: specify the directory path | - |
Batch Conversion (Entire Directory)
# 转换目录下所有 .md 文件
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles
# 批量转换,指定主题
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles --theme tech
One-click Publish (Single Article)
# 首次使用:登录知乎并保存 Cookie
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --login
# 发布文章
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md
# 保存为草稿
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --draft
# 指定标题和话题
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --title "文章标题" --topic "AI,编程"
Batch Publish (Entire Directory)
# 批量发布目录下所有 .md 文件
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles
# 批量保存为草稿
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --draft
# 批量发布,设置话题和自定义间隔(默认60s)
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --topic "AI,编程" --delay 30
| Parameter | Description | Default |
|---|---|---|
--dir |
Batch publish: specify the directory path, publish all .md | - |
--delay |
Seconds between publishing each article (to prevent rate limiting) | 60 |
--draft |
Save as draft only | No |
--topic |
Article topics, comma-separated | - |
Available Themes
- zhihu (Zhihu Blue): Zhihu's official blue tone, professional and clean, recommended as the default
- elegant (Elegant Gray): dark gray tone, steady and grand, suitable for in-depth long-form articles
- tech (Tech Purple): purple/indigo tone, modern tech feel, suitable for technical articles
- warm (Warm Orange): orange warm tone, lively and friendly, suitable for stories/experience sharing
- nature (Natural Green): fresh green tone, natural and comfortable, suitable for popular science/lifestyle articles
Supported Markdown Elements
- Headings (h1-h4), h1 is automatically extracted as the article title
- Paragraphs, justified
- Bold、Italic、Strikethrough
- Hyperlinks (Zhihu supports jumping)
- Ordered/unordered lists, including nesting
- Code blocks (with syntax highlighting and language labels)
- Inline code
- Tables (with zebra striping)
- Blockquotes
- Horizontal rules
- Images (centered and adaptive, with captions)
- Footnotes
- Task lists
Usage Workflow
Method 1: Preview + Manual Paste
- Run the conversion command to generate an HTML file
- Open the generated HTML file in a browser
- Click the "Copy content to clipboard" button at the top of the page
- In the Zhihu article editor,
Ctrl+Vpaste
Method 2: One-click Automatic Publishing
- For first-time use, run
--loginlogin - Run the publish command, and the script will complete publishing automatically
- After successful publishing, the article link will be output
Notes
- The first publish requires logging in to Zhihu through the browser; the Cookie will be saved for subsequent use
- After the Cookie expires, you need to log in again (
--login) - Images must use publicly accessible URLs; local images must first be uploaded to an image host
- Before publishing, it is recommended to check the layout effect in preview mode first
- Zhihu has a limit on article length; for overly long articles, it is recommended to publish them in multiple parts.