Skip to content

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.


Install

bash
npm install @cognipeer/to-markdown
bash
yarn add @cognipeer/to-markdown
bash
pnpm add @cognipeer/to-markdown

Quick example

typescript
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

FormatExtensionsDescription
PDF.pdfPDF documents (optional OCR for scans)
Word.docxMicrosoft Word documents
HTML.html, .htmHTML web pages
Excel.xlsx, .xlsExcel spreadsheets
CSV.csvComma-separated values
Jupyter.ipynbJupyter notebooks
PowerPoint.pptxPowerPoint presentations
XML/RSS.xml, .rss, .atomXML and feed formats
JSON.jsonJSON documents
YAML.yaml, .ymlYAML documents
EPUB.epubEPUB e-books
Outlook.msgOutlook email messages
Images.jpg, .jpeg, .png, .gifImage files (metadata, optional OCR)
Audio.mp3, .wavAudio files (metadata extraction)
Text.txtPlain text files
Archives.zipZIP archives

See Format Support for what each converter extracts.

Where to go next

About

Maintained by Cognipeer and released under the MIT License. Source on GitHub, published on npm.

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub