Lines 1-33typescript
4 * Registers a `doc_to_md` tool that converts a local PDF, DOCX, or PPTX file
5 * to Markdown. Primary engine: pymupdf4llm via ephemeral `uv run --with`
6 * (warm-once per process, no repo venv). Fallback: unpdf pure-JS text
7 * extraction (degraded, explicitly marked). DOCX/PPTX convert to PDF first
8 * via headless soffice, then feed the PDF pipeline. Output over 32 KB or
9 * 1000 lines is spilled to a temp .md file with a 60-line preview; smaller
10 * content is returned inline.
13import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
14import { spawn } from "node:child_process";
15import { tmpdir } from "node:os";
LowWeak Crypto
Package source references weak cryptographic algorithms.
doc_to_md.tsView on unpkg · L13 16import { basename, extname, join, resolve } from "node:path";
17import { createHash } from "node:crypto";
18import { fileURLToPath } from "node:url";
19import { extractText, getDocumentProxy } from "unpdf";
20import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
21import { formatSize, keyHint } from "@earendil-works/pi-coding-agent";
22import { Text } from "@earendil-works/pi-tui";
23import { Type } from "@sinclair/typebox";
27export type InputType = "pdf" | "docx" | "pptx";
28export type Engine = "pymupdf4llm" | "unpdf";
30export interface DocToMdConfig {
31 pymupdfVersion: string;
32 warmTimeoutMs: number;
33 convertTimeoutMs: number;