md-to-zhihu

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown 一键发布到知乎

One-Click Publish Markdown to Zhihu

将 Markdown 文章转换为知乎文章编辑器可接受的格式,支持多种排版风格预览,并可一键发布到知乎专栏。
Convert Markdown articles to a format acceptable to the Zhihu article editor, support preview of multiple typesetting styles, and enable one-click publishing to Zhihu Columns.

快速使用

Quick Start

依赖安装

Dependency Installation

bash
undefined
bash
undefined

格式转换依赖

Dependencies for format conversion

pip install markdown pygments beautifulsoup4
pip install markdown pygments beautifulsoup4

一键发布依赖(可选,仅发布时需要)

Dependencies for one-click publishing (optional, required only for publishing)

pip install playwright requests playwright install chromium
undefined
pip install playwright requests playwright install chromium
undefined

格式转换(单篇)

Format Conversion (Single Article)

bash
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py input.md
参数说明:
参数说明默认值
input.md
输入的 Markdown 文件路径必填
-o output.html
输出 HTML 文件路径
{input}_zhihu.html
--theme
主题风格
zhihu
--content-only
仅输出纯净 HTML 内容(用于 API 发布)
--dir
批量转换:指定目录路径-
bash
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py input.md
Parameter Explanation:
ParameterDescriptionDefault Value
input.md
Path of the input Markdown fileRequired
-o output.html
Path of the output HTML file
{input}_zhihu.html
--theme
Theme style
zhihu
--content-only
Output pure HTML content only (for API publishing)No
--dir
Batch conversion: specify directory path-

批量转换(整个目录)

Batch Conversion (Entire Directory)

bash
undefined
bash
undefined

转换目录下所有 .md 文件

Convert all .md files in the directory

python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles

批量转换,指定主题

Batch conversion with specified theme

python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles --theme tech
undefined
python ~/.cursor/skills/md-to-zhihu/scripts/convert.py --dir ./articles --theme tech
undefined

一键发布(单篇)

One-Click Publishing (Single Article)

bash
undefined
bash
undefined

首次使用:登录知乎并保存 Cookie

First-time use: Log in to Zhihu and save Cookie

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --login
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --login

发布文章

Publish article

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md

保存为草稿

Save as draft

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --draft
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --draft

指定标题和话题

Specify title and topics

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --title "文章标题" --topic "AI,编程"
undefined
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py input.md --title "Article Title" --topic "AI,Programming"
undefined

批量发布(整个目录)

Batch Publishing (Entire Directory)

bash
undefined
bash
undefined

批量发布目录下所有 .md 文件

Batch publish all .md files in the directory

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles

批量保存为草稿

Batch save as drafts

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --draft
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --draft

批量发布,设置话题和自定义间隔(默认60s)

Batch publish with specified topics and custom interval (default 60s)

python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --topic "AI,编程" --delay 30

| 参数 | 说明 | 默认值 |
|------|------|--------|
| `--dir` | 批量发布:指定目录路径,发布所有 .md | - |
| `--delay` | 每篇文章发布间隔秒数(防限流) | `60` |
| `--draft` | 仅保存为草稿 | 否 |
| `--topic` | 文章话题,逗号分隔 | - |
python ~/.cursor/skills/md-to-zhihu/scripts/publish.py --dir ./articles --topic "AI,Programming" --delay 30

| Parameter | Description | Default Value |
|------|------|--------|
| `--dir` | Batch publishing: specify directory path to publish all .md files | - |
| `--delay` | Interval (in seconds) between publishing each article (to avoid rate limits) | `60` |
| `--draft` | Only save as draft | No |
| `--topic` | Article topics, separated by commas | - |

可用主题

Available Themes

  • zhihu (知乎蓝):知乎官方蓝色调,专业简洁,推荐默认使用
  • elegant (优雅灰):深灰色调,沉稳大气,适合深度长文
  • tech (科技紫):紫色/靛蓝色调,现代科技感,适合技术文章
  • warm (温暖橙):橙色暖色调,活泼亲和,适合故事/经验分享
  • nature (自然绿):绿色清新调,自然舒适,适合科普/生活文章
  • zhihu (Zhihu Blue): Zhihu's official blue tone, professional and concise, recommended for default use
  • elegant (Elegant Gray): Dark gray tone, calm and grand, suitable for in-depth long articles
  • tech (Tech Purple): Purple/indigo tone, modern tech feel, suitable for technical articles
  • warm (Warm Orange): Warm orange tone, lively and approachable, suitable for stories/experience sharing
  • nature (Natural Green): Fresh green tone, natural and comfortable, suitable for popular science/life articles

支持的 Markdown 元素

Supported Markdown Elements

  • 标题 (h1-h4),h1 自动提取为文章标题
  • 段落,两端对齐
  • 加粗斜体删除线
  • 超链接(知乎支持跳转)
  • 有序/无序列表,含嵌套
  • 代码块(带语法高亮和语言标签)
  • 行内代码
  • 表格(带斑马纹)
  • 引用块
  • 分割线
  • 图片(居中自适应,带图注)
  • 脚注
  • 任务列表
  • Headings (h1-h4), h1 is automatically extracted as the article title
  • Paragraphs, justified alignment
  • Bold, italic, strikethrough
  • Hyperlinks (Zhihu supports redirection)
  • Ordered/unordered lists, including nested lists
  • Code blocks (with syntax highlighting and language labels)
  • Inline code
  • Tables (with zebra stripes)
  • Blockquotes
  • Horizontal rules
  • Images (centered and adaptive, with captions)
  • Footnotes
  • Task lists

使用流程

Usage Workflow

方式一:预览 + 手动粘贴

Method 1: Preview + Manual Paste

  1. 执行转换命令,生成 HTML 文件
  2. 用浏览器打开生成的 HTML 文件
  3. 点击页面顶部「复制内容到剪贴板」按钮
  4. 在知乎文章编辑器中
    Ctrl+V
    粘贴
  1. Execute the conversion command to generate an HTML file
  2. Open the generated HTML file in a browser
  3. Click the "Copy content to clipboard" button at the top of the page
  4. Paste using
    Ctrl+V
    in the Zhihu article editor

方式二:一键自动发布

Method 2: One-Click Automatic Publishing

  1. 首次使用先运行
    --login
    登录
  2. 执行发布命令,脚本自动完成发布
  3. 发布成功后会输出文章链接
  1. Run
    --login
    to log in for the first use
  2. Execute the publishing command, and the script will complete publishing automatically
  3. The article link will be output after successful publishing

注意事项

Notes

  • 首次发布需要通过浏览器登录知乎,Cookie 会保存供后续使用
  • Cookie 过期后需要重新登录(
    --login
  • 图片需使用可公开访问的 URL,本地图片需先上传到图床
  • 发布前建议先用预览模式检查排版效果
  • 知乎对文章长度有限制,超长文章建议分篇发布
  • First-time publishing requires logging in to Zhihu via browser, and the Cookie will be saved for subsequent use
  • Re-login with
    --login
    is required when the Cookie expires
  • Images must use publicly accessible URLs; local images need to be uploaded to an image hosting service first
  • It is recommended to check the typesetting effect in preview mode before publishing
  • Zhihu has limits on article length; it is recommended to split extra-long articles into multiple parts for publishing