DEV Community

Daniel Igel
Daniel Igel

Posted on

Convert HTML to clean Markdown via REST API — perfect for content migration and web scraping

Scraping a webpage or migrating CMS content means you usually end up with raw HTML — but your pipeline wants clean Markdown for LLM prompts, static-site generators, or readable diffs. Writing a reliable HTML-to-Markdown converter yourself means wrestling with nested tags, code blocks, tables, and <script> noise you don't want in the output.

One POST turns any HTML string into clean Markdown:

curl --request POST \
  --url 'https://html-to-markdown-converter-api.p.rapidapi.com/api/v1/convert' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: html-to-markdown-converter-api.p.rapidapi.com' \
  --header 'Content-Type: application/json' \
  --data '{"html":"<h1>Hello</h1><p>World</p>","options":{"clean":true}}'
Enter fullscreen mode Exit fullscreen mode

You get back { markdown, inputLength, outputLength }. The clean: true option strips <script>, <style>, <iframe>, and ad tags before conversion — exactly what you need when scraping live pages.

Need to convert an entire URL without fetching it yourself? Use the preview endpoint:

const res = await fetch(
  'https://html-to-markdown-converter-api.p.rapidapi.com/api/v1/preview?url=' +
    encodeURIComponent('https://example.com'),
  {
    headers: {
      'x-rapidapi-key': process.env.RAPIDAPI_KEY,
      'x-rapidapi-host': 'html-to-markdown-converter-api.p.rapidapi.com',
    },
  }
);
const { markdown } = await res.json();
Enter fullscreen mode Exit fullscreen mode

For bulk jobs, POST /api/v1/convert/batch accepts up to 10 items in one request. Powered by turndown (MIT) — no external API calls, no rate-limited third-party service.

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/html-to-markdown-converter-api

What's your go-to use case for converting HTML to Markdown — LLM input prep, CMS migration, or something else?

Top comments (0)