agentleFS
TbusOSTbusOS/sky-skills/skills/doc-to-markdown/SKILL.md

doc-to-markdown

Skill3 starsChanged 33 days agoMITView on GitHub

Convert documents (PDF, DOCX) in a directory to well-formatted Markdown files with images extracted. Use this skill whenever the user wants to convert documents to markdown, make documents readable for future reference, extract content from PDFs or Word files into markdown format, or batch-convert a folder of documents. Trigger on phrases like "convert to markdown", "转成markdown", "转换成md", "文档转换", "把文档变成可读的", "提取文档内容", or any request involving turning PDF/DOCX files into a text-based readable format with images preserved. Not for the reverse direction: to turn Markdown into PDF, use md-to-pdf instead.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After the script runs, the output needs human-guided curation to become truly useful.

    line 71
  2. Distinctive:

    Update the markdown references to match

    line 82

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Doc-to-Markdown Converter

Convert PDF and DOCX files to clean Markdown with extracted images. Supports single file or batch directory conversion.

Output Structure

<output-dir>/
├── <doc1-name>.md
├── <doc2-name>.md
└── images/
    ├── <doc1-slug>/
    │   ├── sec01_01.png
    │   ├── sec01_02_boot_flow.png
    │   └── sec02_01.png
    └── <doc2-slug>/
        └── ...

Image naming convention: sec{章节号}_{序号}_{描述}.png — makes images easy to find and associate with document章节。

Workflow

1. Confirm with user

Identify the source (single file or directory) and confirm:

  • What to convert
  • Where to put output (default: create a markdown/ dir in project root, or user can specify)

2. Ensure dependencies

python3 -c "import fitz" 2>/dev/null || pip3 install pymupdf
python3 -c "from docx import Document" 2>/dev/null || pip3 install python-docx

3. Run the converter

The bundled scripts/convert.py handles the core conversion.

Single file:

python3 <skill-dir>/scripts/convert.py /path/to/file.pdf --output /project/markdown/

Batch directory:

python3 <skill-dir>/scripts/convert.py /path/to/docs/ --output /project/markdown/

What the script handles:

  • PDF: Extracts text with heading detection, extracts embedded images per page. For scanned PDFs (no text layer), exports full page as 2x PNG.
  • DOCX: Extracts text preserving heading/list/code styles, extracts PNG/JPEG images, attempts EMF/WMF conversion via LibreOffice or PIL.
  • Image placement: Images are inserted inline near the paragraphs that reference them, not dumped at the end.
  • Tables: Converted to markdown table format.

4. Post-processing (important!)

After the script runs, the output needs human-guided curation to become truly useful. This is where you add value beyond raw conversion:

  1. Read the generated markdown to verify text quality — fix garbled headings, broken lists, or misformatted code blocks.
  2. Review extracted images — read the image files to check which are:
    • Substantive (diagrams, flowcharts, architecture drawings, code screenshots) → keep
    • Decorative (logos, horizontal rules, tiny icons, blank images) → delete
  3. Rename images to descriptive names based on content:
    • sec01_01.png → sec01_01_验签流程图.png (if it shows verification flow)
    • sec03_02.png → sec03_02_efuse_layout.png (if it shows eFuse layout)
    • Update the markdown references to match
  4. For EMF/WMF diagrams that couldn't be extracted: If the user provides a screenshot or describes the diagram, recreate it using Python PIL and save as PNG. This is common for Visio diagrams embedded in Word docs — they're the most valuable images and worth recreating.
  5. Place images contextually — if images ended up in "Other Images" section at the end, move the ![...]() references to where they logically belong in the text.

5. Report results

Show the user:

  • File tree of what was generated
  • Number of images kept vs removed
  • Any EMF/WMF files that couldn't be converted (suggest user provide screenshots from original doc)
  • Any issues encountered

Edge Cases

  • Scanned PDFs: Page images are exported as fallback; text will be empty. Note this in the markdown.
  • Password-protected PDFs: Report to user if PyMuPDF can't open.
  • Large PDFs (>50 pages): Still convert, but warn user. Consider extracting only pages with figures.
  • Chinese content: PyMuPDF and python-docx handle CJK well, no special handling needed.
  • Complex tables with merged cells: Best-effort markdown tables; suggest "see original" for very complex ones.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.