用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/zhizhunbao/ai-dev-config --skill docx-to-md命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | docx-to-md |
| description | Word 文档转 Markdown。Use when (1) 将 .docx 转换为 .md, (2) 提取 Word 文档内容, (3) 批量转换文档, (4) 保留格式和图片, (5) 自动化文档处理 |
Mammoth is the recommended tool:
CRITICAL: Only convert format, never modify content.
import mammoth
from pathlib import Path
def docx_to_md_mammoth(docx_path: Path, md_path: Path):
"""
Convert DOCX to Markdown using mammoth.
CRITICAL: This function only converts format.
It does NOT modify any content, titles, or text.
"""
with open(docx_path, 'rb') as docx_file:
result = mammoth.convert_to_markdown(docx_file)
md_path.write_text(result.value, encoding='utf-8')
# Print warnings
for message in result.messages:
print(f"Warning: {message}")
return md_path
# Install mammoth
uv add mammoth
from pathlib import Path
import mammoth
def batch_convert(input_dir: Path, output_dir: Path):
"""Convert all DOCX files in directory."""
output_dir.mkdir(parents=True, exist_ok=True)
for docx_file in input_dir.glob('*.docx'):
if docx_file.name.startswith('~$'): # Skip temp files
continue
md_file = output_dir / f"{docx_file.stem}.md"
with open(docx_file, 'rb') as f:
result = mammoth.convert_to_markdown(f)
md_file.write_text(result.value, encoding='utf-8')
print(f"✓ Converted: {docx_file.name} -> {md_file.name}")
import subprocess
from pathlib import Path
def convert_with_images(docx_path: Path, output_dir: Path):
"""Convert DOCX and organize images."""
md_path = output_dir / f"{docx_path.stem}.md"
images_dir = output_dir / 'images'
# Convert
subprocess.run([
'pandoc',
str(docx_path),
'-o', str(md_path),
'--extract-media', str(images_dir)
])
# Update image paths in markdown
content = md_path.read_text(encoding='utf-8')
content = content.replace('](media/', '](images/')
md_path.write_text(content, encoding='utf-8')
return md_path
def convert_lab_template(docx_path: Path, output_path: Path):
"""Convert lab answer document with specific formatting."""
# Convert
subprocess.run([
'pandoc',
str(docx_path),
'-o', str(output_path),
'--wrap=none',
'--atx-headers'
])
# Post-process: Add front matter
content = output_path.read_text(encoding='utf-8')
front_matter = """---
title: Lab Assignment
author: Your Name
date: 2026-01-22
---
"""
output_path.write_text(front_matter + content, encoding='utf-8')
def insert_screenshots(md_path: Path, images_dir: Path):
"""Automatically insert screenshots into markdown."""
content = md_path.read_text(encoding='utf-8')
# Find all image files
images = sorted(images_dir.glob('*.png'))
# Insert images at appropriate locations
for i, img in enumerate(images, 1):
marker = f"<!-- INSERT_IMAGE_{i} -->"
if marker in content:
img_markdown = f"})\n"
content = content.replace(marker, img_markdown)
md_path.write_text(content, encoding='utf-8')
# Install mammoth
uv add mammoth
Images not extracted → Mammoth converts images to base64 embedded in markdown
Chinese characters garbled → Ensure UTF-8 encoding when writing file
Tables broken → Mammoth handles simple tables, complex tables may need manual adjustment
Formatting lost → Mammoth preserves basic formatting (bold, italic, headings, lists)
Temp files (~$*.docx) → Skip files starting with ~$ in batch processing
Use provided scripts for common tasks:
# Convert single file
uv run python .skills/dev-docx_to_md/scripts/convert_docx_mammoth.py input.docx output.md
# Batch convert
uv run python .skills/dev-docx_to_md/scripts/batch_convert.py input_dir/ output_dir/
For detailed examples: See references/examples.md
For pandoc filters: See references/filters.md
For troubleshooting: See references/troubleshooting.md
# Install
uv add mammoth
# Convert single file (Python)
uv run python -c "import mammoth; print(mammoth.convert_to_markdown(open('input.docx', 'rb')).value)" > output.md
# Or use helper script
uv run python .skills/dev-docx_to_md/scripts/convert_docx_mammoth.py input.docx output.md