Skip to main content
The convert operation transforms documents between formats without writing custom code. Convert HTML to clean Markdown, render Markdown to HTML, extract Word documents, extract text from PDFs, or parse frontmatter metadata.
The convert operation uses Workers-compatible libraries: turndown for HTML→Markdown, marked for Markdown→HTML, gray-matter for frontmatter, mammoth for DOCX, and unpdf for PDF text extraction. DOCX and PDF require nodejs_compat.

Quick Start

HTML to Markdown:
Markdown to HTML:
Extract Frontmatter:
PDF to Text:

Configuration

Supported Conversions

HTML to Markdown

Converts HTML to clean Markdown using turndown with GitHub Flavored Markdown (GFM) support.
Output:

Turndown Options

Customize the Markdown output:

GFM Table Support

Tables are automatically converted:
Output:

Markdown to HTML

Renders Markdown to HTML using marked with GFM support.
Output:

Marked Options

Code Block Syntax Highlighting

Code blocks preserve language hints for syntax highlighting:
from: markdown to: html

Frontmatter Extraction

Parses YAML frontmatter from Markdown documents using gray-matter.
Output:

Using Extracted Data

HTML to Text

Strips all HTML tags and returns plain text. Useful for search indexing, text analysis, or email plain-text versions.
Output:
Features:
  • Removes <script> and <style> tags completely
  • Decodes HTML entities (&amp;&, &lt;<)
  • Normalizes whitespace

DOCX Conversion

DOCX conversion requires the nodejs_compat compatibility flag in your wrangler.toml. This enables Node.js APIs needed by the mammoth library.
Convert Word documents to HTML or Markdown using mammoth.

DOCX to Markdown

DOCX to Markdown internally converts to HTML first, then to Markdown using turndown. This preserves formatting like headings, lists, and tables.

PDF Text Extraction

PDF text extraction requires the nodejs_compat compatibility flag in your wrangler.toml. This enables Node.js APIs needed by the unpdf library.
Extract text content from PDF documents using unpdf, a Workers-compatible PDF library built on PDF.js.

PDF Options

Control how pages are merged:

Multi-page Documents

By default, text from all pages is merged with double newlines:

PDF Processing Pipeline

Extract PDF text and process it further:

PDF Input Validation

PDF conversion requires an ArrayBuffer (binary data from R2/storage):
Error: convert: PDF input must be an ArrayBuffer (use storage operation to read the file)

Examples

Web Scraping Pipeline

Blog Post Processor

Email with Plain Text Fallback

Document Migration Pipeline

Error Handling

Invalid Conversion

Error: convert: unsupported conversion text → pdf. Supported: html→markdown, html→text, markdown→html, markdown→frontmatter, docx→markdown, docx→html, pdf→text

Empty Input

Empty strings are handled gracefully:
Output: "" (empty string) For frontmatter, empty input returns:

DOCX Input Validation

DOCX conversion requires an ArrayBuffer:
Error: convert: DOCX input must be an ArrayBuffer (use storage operation to read the file)

Performance

Convert operations are fast and efficient:
  • transform - Declarative data transformations
  • html - HTML template rendering
  • storage - Read/write files for conversion
  • http - Fetch web pages to convert