Library
to-markdown
A versatile, TypeScript-first utility for turning files into Markdown. One promise-based call handles PDF, Word, HTML, spreadsheets, notebooks, feeds, archives, and media — with optional OCR for scanned pages and images.
- Package
@cognipeer/to-markdown - Licence MIT
- Runtime Node.js 18+
@cognipeer/to-markdown exists because retrieval pipelines, prompt contexts, and knowledge bases all want the same thing: clean Markdown, whatever the source file happened to be. Point it at a path, a Buffer, or a base64 string and it detects the format, picks the right converter, and hands back a Markdown string.
Getting started
Install the package and run your first conversion from a path, a Buffer, or base64.
Format support
What each converter does, format by format, with example output.
OCR
Read text out of scanned PDFs and images with Tesseract or a vision model.
API overview
Every exported function and type, with signatures and return values.
Install
npm install @cognipeer/to-markdownyarn add @cognipeer/to-markdownpnpm add @cognipeer/to-markdownQuick example
import { convertToMarkdown } from '@cognipeer/to-markdown';
// Convert a PDF file
const markdown = await convertToMarkdown('./document.pdf');
console.log(markdown);What it does
Detects the format for you
File extension, MIME type from a data URL, or magic bytes in a raw Buffer — with a plain-text fallback and a forceExtension escape hatch.
One converter per format
Each format has a specialised converter, so tables stay tables, notebook cells stay ordered, and feeds keep their structure.
TypeScript throughout
Written in TypeScript and shipped with full type definitions, as both ESM and CommonJS builds.
Supported formats
| Format | Extensions | Description |
|---|---|---|
.pdf | PDF documents (optional OCR for scans) | |
| Word | .docx | Microsoft Word documents |
| HTML | .html, .htm | HTML web pages |
| Excel | .xlsx, .xls | Excel spreadsheets |
| CSV | .csv | Comma-separated values |
| Jupyter | .ipynb | Jupyter notebooks |
| PowerPoint | .pptx | PowerPoint presentations |
| XML/RSS | .xml, .rss, .atom | XML and feed formats |
| JSON | .json | JSON documents |
| YAML | .yaml, .yml | YAML documents |
| EPUB | .epub | EPUB e-books |
| Outlook | .msg | Outlook email messages |
| Images | .jpg, .jpeg, .png, .gif | Image files (metadata, optional OCR) |
| Audio | .mp3, .wav | Audio files (metadata extraction) |
| Text | .txt | Plain text files |
| Archives | .zip | ZIP archives |
See Format Support for what each converter extracts.
Where to go next
- Getting Started — installation and the three input shapes.
- Converter Options — every option on
ConverterOptions, with defaults. - Format Support — format-by-format behaviour and sample output.
- Error Handling — failure modes, retries, and fallbacks.
About
Maintained by Cognipeer and released under the MIT License. Source on GitHub, published on npm.

