Asset 20 8 2
Does AI recommend your business? Run the free check →

Join 15,000 business owners, marketers and entrepreneurs. The Sunday newsletter you'll be annoyed only arrives once a week.

Article

How to Convert HTML to Markdown With Pandoc

To convert HTML to Markdown, install Pandoc, then run pandoc -f html -t markdown page.html -o page.md in your terminal. Check the result afterwards, because complex tables and some layout may not survive the conversion.

The short answer on what Pandoc does

Pandoc is a command line converter, and it'll turn a saved HTML file or a live web page into a Markdown file you can edit.

Steps to convert HTML to Markdown with Pandoc

  1. Install Pandoc, then open a terminal in the folder that holds your HTML file.
  2. Run pandoc -f html -t markdown page.html -o page.md. The -f flag names the input format and -t names the output. If you leave both out, Pandoc tries to guess the formats from the file extensions.
  3. Keep the -o (or --output) part. Without it, the Markdown is printed to the terminal window (stdout) rather than saved as a file.
  4. Want GitHub style output? Swap -t markdown for -t gfm, which is GitHub-Flavored Markdown. Don't reach for the older markdown_github format, as it's deprecated and less accurate.
  5. To convert a live web page, give its address where the file name would go and Pandoc fetches it over HTTP. Pandoc's own demos page uses pandoc -s -r html https://pandoc.org/ -o example12.text. If the site needs a custom User-Agent or another header, add --request-header.
  6. Add --wrap=none to stop line wrapping and --extract-media=media to save images and other media into a folder. Pandoc adjusts the image references in the Markdown to point at those saved copies, and it can write them to a zip in place of a folder.
  7. Open the new Markdown file and check the headings, links, tables and images before you use it.

Once the file is converted, you'll want somewhere comfortable to edit it. My roundup of the best Markdown editors covers the options, and if you're on a Mac, this list of Markdown editors for Mac narrows it down. Need the content back out as a document to share? These Markdown to PDF converters handle that next step.

When the output doesn't look right

Lines break in odd places. The --wrap option takes auto, none or preserve. Auto is the default and wraps text to 72 columns unless you change that with --columns. Use none to stop line wrapping; preserve is the third option.

Headings use a different style from the one you want. --markdown-headings picks between atx and setext headings. Atx, where each heading starts with # signs, is the default.

Links clutter the text. Pandoc writes inline links by default. Add --reference-links and it'll write reference style links instead.

Odd characters appear. Pandoc uses UTF-8 for input and output. If your HTML is saved in another encoding, pipe it through iconv first.

Work with me

Want AI doing the heavy lifting in your marketing?

I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.

Your table broke. Complex tables may not fit Pandoc's document model, so check every table against the original page. Rebuild it by hand in the Markdown, or keep it as HTML. On that last point, the raw_html extension, which keeps HTML that Markdown can't represent as raw HTML, is switched off by default when the input is HTML.

What Pandoc won't carry across

According to Pandoc's documentation, it keeps structural elements, but not presentation details like margin size, and conversions can be lossy.

Don't assume menus, sidebars or scripts on a web page will be stripped out either. When you convert a live page, expect to tidy the file and delete the navigation text by hand.

If you're converting HTML you didn't write, or a page from a site you don't control, the documentation says anyone using Pandoc on untrusted input should add --sandbox.

The converter I'd reach for

Run Pandoc with -t gfm, --wrap=none and --extract-media=media on one command, then read the file line by line before publishing it. Leave time for fixing tables and cutting leftover menu text, because that part's on you.

Published and maintained by the Lilach Bullock team, covering marketing, AI and business growth.
Your buyers are asking AI who to use. Does it say you?

See for free whether ChatGPT, Claude, Perplexity, Gemini and Google name you, and get the plan to become the answer.

Check my AI visibility →
Sundays only

Get the Sunday newsletter.

One email a week. AI experiments, marketing tactics, and the workflows Lilach is building right now in her own business.

Subscribe free

Let’s get your marketing running on AI.

Book a free 30-minute call

We figure out what you need, where AI fits in, and what working together would look like.

Book the call →

Or take the 30-second calculator

You’ll see the hours and the money quietly leaking out of your week, and the three workflows worth building first.

Take the calculator →

Or grab the free AI resource library

Prompt packs, templates, checklists, and swipe files. The exact tools I build for paying clients. Yours, free.

Get the library →
Keep reading

More from the blog.