Skip to content

A simple Cloudflare Worker to convert markdown to html.

Notifications You must be signed in to change notification settings

schardev/markdown-to-html-worker

Repository files navigation

markdown-to-html-worker

A simple Cloudflare Worker to convert markdown to html.

  • Sanitizes incoming HTML
  • Supports code highlighting using rehype-pretty-code
  • Supports Github markdown flavor
  • Uses rehype-remark ecosystem to easily extend configuration

Getting Started

Clone this repository and install required packages:

# clone repo
git clone https://github.com/schardev/markdown-to-html-worker

# install packages
cd markdown-to-html-worker && pnpm install

Running pnpm dev will start the dev server on https://localhost:8787.

Sending markdown text

To send the markdown text do a POST request to the running server (make sure you set Content-Type to text/plain).

const markdownText = `# this is markdown heading\nthis is a paragraph`;

// ...
const res = await fetch("https://localhost:8787", {
  method: "POST",
  body: markdownText,
});

console.log(await res.text());
// will log:
//
// <h1>this is markdown heading</h1>
// <p>this is a paragraph</p>

Environment variables

ALLOWED_HOSTNAMES - Hostnames to allow cross-origin requests from. Leaving empty will disable CORS.

About

A simple Cloudflare Worker to convert markdown to html.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published