Developer/Products/to-markdown

to-markdown

@cognipeer/to-markdown  ·  Utilities
stable

A TypeScript-first utility that converts 20+ formats — PDF, DOCX, PPTX, XLSX/CSV, HTML, Jupyter notebooks, ZIP archives, RSS/Atom, images, and audio — into clean Markdown, ready for RAG pipelines and LLM context windows.

License  ·  MITTypeScript  ·  100%Audience  ·  Anyone building aFits  ·  RAG ingestion
RAG ingestionDocument normalisationTypeScript-firstBrowse recipes
Production install
$npm install @cognipeer/to-markdown

What's in the box

Anyone building a RAG pipeline or document workflow that needs to normalise heterogeneous file formats into a single, LLM-friendly representation. Each capability is opt-in — use the parts that fit, leave the rest.

20+ formats

PDF, DOCX, PPTX, XLSX, CSV, HTML, IPYNB, ZIP, XML/RSS/Atom, images, and audio — all through one convert call.

Promise-based API

`convertToMarkdown(input)` takes a path, Buffer, or base64 string and returns a Markdown string with auto format detection.

TypeScript first

Written in TypeScript with full type definitions and zero-config import in modern toolchains.

AI-ready rich output

`convertToRichMarkdown` adds frontmatter, a section tree, and optional token-aware RAG chunks for ingestion.

Optional OCR

Opt-in image and scanned-PDF OCR via the tesseract.js peer dependency, with auto / always / never PDF modes.

Modular & fast

Per-format converters keep the bundle lean — only load the adapters you actually need.

How it runs

A small, modular pipeline: detect the source format, run the right adapter, normalise the structure, and emit clean Markdown — ready to chunk and embed.

Step 1
Detect
Format sniff
Step 2
Adapter
PDF · DOCX · HTML …
Step 3
Normalise
Headings · tables
Step 4
Emit
Markdown string

Inputs

  • PDF · DOCX
  • HTML · plain text
  • Excel · CSV
  • Bring-your-own buffer

Options

  • imageMode
  • tableStrategy
  • headingDepth
  • chunkHint

Output

  • Clean Markdown
  • Stable headings
  • Per-doc metadata
  • Streaming-friendly

Quickstart

Install, configure, run. The example below is the smallest piece of code that does something useful in production.

1import { convertToMarkdown, convertToRichMarkdown } from "@cognipeer/to-markdown";
2 
3// Path, Buffer, or base64 — format auto-detected
4const md = await convertToMarkdown("./policies/handbook.pdf");
5console.log(md);  // clean Markdown string
6 
7// AI-ready: frontmatter, sections, and RAG chunks
8const doc = await convertToRichMarkdown("./report.docx", {
9  includeChunks: true,
10  chunkOptions: { maxTokens: 800 },
11});
12console.log(doc.chunks, doc.sections);

How it compares

Against the utilities options teams most often weigh — focused on operational concerns, not feature inventories.

Capabilityto-markdownpandocunstructured.ioturndown
PDF●  native◐  partial●  native○  missing
DOCX / PPTX●  native●  native●  native○  missing
HTML●  native●  native●  native●  native
Excel / CSV●  native◐  partial●  native○  missing
TypeScript●  native○  missing○  missing●  native
Open source●  native●  native◐  partial●  native

Next steps