Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

πŸ”₯ HTML Markdowner API

A blazingly fast API server that converts HTML pages to clean Markdown format. Built with Bun, Hono, and Redis.

Features

  • ✨ Convert any static HTML/SSR page to Markdown
  • πŸš€ Fast and efficient with Redis caching
  • πŸ›‘οΈ Rate limiting by IP (5 requests per minute)
  • 🎯 Clean article extraction using Mozilla Readability
  • πŸ“š Interactive API documentation with Scalar
  • 🐳 Docker-ready for easy deployment
  • ⚑ Built with Bun for maximum performance
  • πŸ”§ Type-safe validation with Zod
  • πŸ“‹ OpenAPI 3.1 specification

Tech Stack

Prerequisites

  • Bun >= 1.0
  • Redis >= 7.0 (or use Docker Compose)

Installation

# Clone the repository
git clone <your-repo-url>cd htmlmarkdowner
# Install dependencies
bun install
# Start Redis with Docker (recommended)
bun run docker:redis
# Run the development server
bun run dev

Environment Variables

Create a .env file in the root directory:

PORT=3000NODE_ENV=developmentREDIS_URL=redis://localhost:6379

API Documentation

Interactive Documentation

Visit http://localhost:3000 to access the interactive API documentation powered by Scalar. The documentation is auto-generated from OpenAPI 3.1 specifications.

Endpoints

GET /

Returns the interactive API documentation page using Scalar.

GET /convert

Convert URL to Markdown.

Query Parameters:

  • url (required): The URL to convert to Markdown (must be a valid HTTP/HTTPS URL)
  • enableDetailedResponse (optional): Return full page content instead of just article content (default: false)

Headers:

  • Accept: application/json - Returns JSON array with markdown content
  • Accept: text/plain - Returns plain text markdown (default)

GET /health

Health check endpoint that verifies Redis connection.

Examples

Single Page (Text Response)

curl "http://localhost:3000/convert?url=https://example.com"

Single Page (JSON Response)

curl -H "Accept: application/json" \
"http://localhost:3000/convert?url=https://example.com"

Response:

[
{
"url": "https://example.com",
"md": "# Example Domain\n\nThis domain is for use in illustrative examples..."
}
]

Detailed Response (Full Page Content)

curl "http://localhost:3000/convert?url=https://example.com&enableDetailedResponse=true"

Rate Limiting

  • Limit: 5 requests per minute per IP address
  • Scope: Per IP address (supports proxy headers: CF-Connecting-IP, X-Forwarded-For, X-Real-IP)
  • Headers: Rate limit info included in response headers (RateLimit-*)
  • Storage: Redis with rate-limit-redis
  • Standard: IETF Draft 7 compliant

Building Standalone Executable

The project can be built into a single standalone executable using Bun's --compile flag. This significantly reduces startup time and simplifies deployment.

# Build the executable
bun run build
# Run it directly (no dependencies needed!)
./htmlmarkdowner

The executable:

  • βœ… Contains all dependencies bundled
  • βœ… No need for node_modules in production
  • βœ… Faster cold start times (~50ms vs ~200ms)
  • βœ… Single binary deployment
  • βœ… Minified and optimized
  • βœ… Cross-platform support

Docker Deployment

Local Development (Redis Only)

For local development, run only Redis in Docker and the app directly with Bun:

# Start Redis
bun run docker:redis
# In another terminal, run the app
bun run dev
# Stop Redis when done
bun run docker:redis:down

The services will be available at:

Production Deployment (Full Stack)

For production, use the production compose file that runs both Redis and the app:

# Build and start all services (API available on port 3000 by default)
bun run docker:prod:up
# Or set custom host port
HOST_PORT=8080 bun run docker:prod:up
# View logs
bun run docker:prod:logs
# Stop services
bun run docker:prod:down
# Stop and remove volumes
docker-compose -f docker-compose.prod.yml down -v

The services will be available at:

Environment Variables:

  • HOST_PORT: Host port for the API (default: 3000)

Using Docker Only

# Start Redis
docker run -d --name redis -p 6379:6379 redis:7-alpine
# Build the app
docker build -t htmlmarkdowner .# Run the app (default port 3000)
docker run -d \
--name htmlmarkdowner \
-p 3000:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner
# Or run on custom port
docker run -d \
--name htmlmarkdowner \
-p 8080:3000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
htmlmarkdowner

Production Deployment on VM

  1. Install Docker and Docker Compose on your VM:
# Update packages
sudo apt update
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Install Docker Compose
sudo apt install docker-compose-plugin
  1. Clone and configure:
git clone <your-repo-url>cd htmlmarkdowner
# Optional: Set environment variables for custom configurationexport HOST_PORT=8080 # Custom host port (default: 3000)# PORT=3000 and REDIS_URL are set in docker-compose.prod.yml
  1. Deploy:
# Build and start (using production compose file)
sudo docker-compose -f docker-compose.prod.yml up -d
# Check status
sudo docker-compose -f docker-compose.prod.yml ps
# View logs
sudo docker-compose -f docker-compose.prod.yml logs -f app

Development

Available Scripts

# Development
bun run dev # Run in development mode with hot reload
bun run start # Run production server (src/index.ts)# Building
bun run build # Build standalone executable with minification# Code Quality
bun run format # Format code with Biome
bun run format:check # Check code formatting
bun run lint # Lint and fix code with Biome
bun run lint:check # Check linting without fixing
bun run check # Run both formatting and linting
bun run check:ci # CI-friendly check (no fixes)# Docker
bun run docker:redis # Start Redis container for development
bun run docker:redis:down # Stop Redis container
bun run docker:prod:build # Build production Docker image
bun run docker:prod:up # Start production stack
bun run docker:prod:down # Stop production stack
bun run docker:prod:logs # View production logs

Development Setup

  1. Install dependencies:

    bun install
  2. Start Redis (choose one):

    # Option 1: Docker (recommended)
    bun run docker:redis
    # Option 2: Local Redis installation
    redis-server
  3. Run development server:

    bun run dev
  4. Access the application:

Code Quality

The project uses Biome for fast linting and formatting:

  • Formatting: Tab indentation, double quotes
  • Linting: Recommended rules enabled
  • Import Organization: Automatic import sorting

Project Structure

htmlmarkdowner/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── redis.ts # Redis client configuration
β”‚ β”œβ”€β”€ lib/
β”‚ β”‚ β”œβ”€β”€ markdown.ts # HTML to Markdown conversion logic
β”‚ β”‚ └── validation.ts # Zod schemas and validation helpers
β”‚ β”œβ”€β”€ middleware/
β”‚ β”‚ └── rate-limiter.ts # Rate limiting middleware
β”‚ β”œβ”€β”€ routes/
β”‚ β”‚ β”œβ”€β”€ convert.ts # URL conversion endpoint
β”‚ β”‚ β”œβ”€β”€ health.ts # Health check endpoint
β”‚ β”‚ └── index.ts # Route mounting and OpenAPI setup
β”‚ └── index.ts # Main application entry point
β”œβ”€β”€ Dockerfile # Multi-stage Docker build
β”œβ”€β”€ docker-compose.yml # Development Redis setup
β”œβ”€β”€ docker-compose.prod.yml # Production deployment
β”œβ”€β”€ biome.json # Linting and formatting configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── README.md # This file

How It Works

  1. Request Validation: Zod schemas validate and transform incoming URL parameters
  2. Rate Limiting: Redis-backed rate limiter checks IP-based request limits
  3. Fetch HTML: Uses native fetch with browser User-Agent to get page content
  4. Parse & Extract: JSDOM creates DOM, Readability extracts article content (or full body if detailed response requested)
  5. Clean HTML: Removes unwanted elements (scripts, styles, iframes, etc.)
  6. Convert: Turndown converts cleaned HTML to clean Markdown with ATX headings and fenced code blocks
  7. Return: Sends markdown response in requested format (JSON or plain text)

Docker Build Process

The multi-stage Dockerfile optimizes for both build speed and runtime efficiency:

  1. Builder Stage (oven/bun:1):

    • Installs all dependencies (including dev dependencies)
    • Copies source code
    • Builds standalone executable with bun build --compile --minify --sourcemap --target bun
  2. Production Stage (debian:bookworm-slim):

    • Minimal base image (~78MB) with only essential runtime dependencies
    • Installs ca-certificates for HTTPS requests
    • Copies only the compiled binary (no source code or dependencies)
    • Exposes port 3000 and sets production environment
  3. Result: Production image (~150MB) with fast startup times and no unnecessary dependencies

Differences from Original Markdowner

  • ❌ No Puppeteer: Uses fetch for static HTML (much lighter & faster)
  • ❌ No Cloudflare Workers: Runs on any Node.js/Bun environment
  • ❌ No Twitter/X Support: Focused on standard HTML pages
  • βœ… Simpler Stack: Easier to deploy and maintain
  • βœ… Better Validation: Zod for type-safe validation
  • βœ… Docker Ready: Easy deployment with Docker Compose
  • βœ… Standalone Executable: Single binary with all dependencies bundled

Troubleshooting

Redis Connection Issues

# Check if Redis is running
redis-cli ping
# Should return: PONG# Check Docker Redis logs
docker-compose logs redis

Port Already in Use

# Change PORT in .env or docker-compose.yml
PORT=3001

Rate Limit Issues

# Clear rate limit for an IP in Redis
redis-cli DEL "hrl:{IP_ADDRESS}"

Credits

This project is an alternative implementation of markdowner by supermemoryai. While the original markdowner uses Puppeteer for dynamic content rendering, htmlmarkdowner focuses on static/SSR pages with a simpler stack.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

About

A blazingly fast API to convert static HTML/SSR pages to clean Markdown format. Alternative to markdowner without Puppeteer. Built with Bun, Hono & Redis. 🐳 Docker-ready. ⚑

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages