StringMash.com

HTML to Markdown

Pull readable Markdown out of a page, and lose the parts Markdown cannot hold.

Conversion
104 characters
Updates as you type
Markers escaped

Using the converter

Paste HTML on the left and Markdown appears on the right. Swap the boxes to go back the other way.

Script and style elements are dropped rather than converted, because their contents are code that would otherwise land in your document as text. Markdown's own markers are escaped in the output, so an asterisk in the HTML comes out as \* and does not turn into emphasis on the way back.

This direction loses things

HTML can say more than Markdown can. A span with a class, a nested table, a definition list, an inline style, an id used as an anchor target: none of these has a Markdown spelling, so the converter keeps the text and drops the wrapper.

Whitespace goes too. HTML collapses runs of spaces when it renders, so this does the same, and a document that relied on preformatted spacing outside a pre element will not come back the same.

That is the trade the format was designed around. Gruber's stated goal was that the source should read as plain text, and anything that cannot be written plainly is not in the language.

Aaron Swartz wrote the first one

Markdown came out of a collaboration between John Gruber and Aaron Swartz in 2004. Swartz, then 17, worked on the syntax with Gruber and wrote html2text, a Python script that did exactly what this page does.

His reasoning was practical. He wanted to take a page off the web, edit it as text and put it back, and there was no way to get out of HTML once you were in it. html2text is still maintained and still used inside larger tools.

Swartz also wrote atx, the heading format Markdown borrowed, and worked on RSS 1.0 and the early Creative Commons licences. He died in 2013, aged 26, while facing federal charges over bulk-downloading academic papers from JSTOR.

Related conversions

Markdown to HTML is the forward direction, and it explains why the two formats disagree about so much. XML to JSON uses the same tag parser underneath, pointed at data rather than at prose.

Text rescued from a web page often needs line breaks removed before it reads properly.

Questions

How do I convert HTML to Markdown?

Paste the HTML above and copy the Markdown. It runs in your browser, so nothing is sent anywhere.

What gets lost?

Anything Markdown cannot express: classes, ids, inline styles, spans, nested tables and definition lists. The text inside them is kept and the wrapper is dropped.

Are script and style tags converted?

No, they are dropped. Their contents are code, and converting them would drop JavaScript into your document as prose.

Why are there backslashes in the output?

Markdown's markers are escaped, so a literal asterisk in the HTML does not turn into emphasis when the Markdown is rendered.