# docx-to-md

Convert Word documents (`.docx` / `.doc`) into clean Markdown (`.md`), one file
per source. Optionally move each source into a "processed" folder after it
converts successfully.

Handles modern `.docx` (zip/OOXML) via MarkItDown, and legacy binary `.doc`
(OLE2) via a headless Word filtered-HTML fallback, including files that are
secretly legacy `.doc` behind a `.docx` extension.

## Quick start

Batch a folder (robust: per-file timeout, safe resume, move-on-success):

```powershell
python "C:\Users\<you>\.copilot\m-skills\docx-to-md\batch.py" `
  --input-dir     "C:\path\Raw" `
  --out           "C:\path\Output" `
  --processed-dir "C:\path\Raw\Processed" `
  --log           "C:\path\batch.log" `
  --result        "C:\path\summary.json" `
  --timeout 180 --skip-existing
```

One or a few files:

```powershell
python "C:\Users\<you>\.copilot\m-skills\docx-to-md\convert.py" `
  --input "C:\path\a.docx" --out "C:\path\Output" [--processed-dir "C:\path\Processed"]
```

## Options

| Flag              | Purpose                                                          |
| ----------------- | --------------------------------------------------------------- |
| `--input`         | A source file. Repeat for multiple (convert.py).                |
| `--input-dir`     | Convert every `.docx`/`.doc` in a folder (non-recursive).       |
| `--out`           | Output directory for `.md` files.                               |
| `--processed-dir` | Move each source here after a successful conversion.            |
| `--skip-existing` | Skip files whose `.md` already exists (safe resume).            |
| `--timeout`       | (batch.py) Per-file timeout in seconds, default 180.            |

## Behavior

- Move happens only on success; failed/timed-out files stay in place.
- Legacy fallback normalizes encoding (fixes smart quotes / dashes) to UTF-8.
- OneDrive cloud files are hydrated via a temp copy before conversion.
- A document that hangs Word is isolated and skipped; only that spawned Word
  instance is killed.

## Requirements

Python 3.12 with `markitdown[docx]`; Microsoft Word (headless COM) for legacy
files. Install markitdown docx support with:
`python -m pip install "markitdown[docx]"`.

See `SKILL.md` for the full agent workflow, QA guidance, and edge cases.
