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:Configuration
Supported Conversions
HTML to Markdown
Converts HTML to clean Markdown using turndown with GitHub Flavored Markdown (GFM) support.Turndown Options
Customize the Markdown output:GFM Table Support
Tables are automatically converted:Markdown to HTML
Renders Markdown to HTML using marked with GFM support.Marked Options
Code Block Syntax Highlighting
Code blocks preserve language hints for syntax highlighting:Frontmatter Extraction
Parses YAML frontmatter from Markdown documents using gray-matter.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.- Removes
<script>and<style>tags completely - Decodes HTML entities (
&→&,<→<) - Normalizes whitespace
DOCX Conversion
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
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):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
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:"" (empty string)
For frontmatter, empty input returns:
DOCX Input Validation
DOCX conversion requires an ArrayBuffer:convert: DOCX input must be an ArrayBuffer (use storage operation to read the file)

