Skip to main content
Develop Tools
← Return to usage guide

Convert HTML to Markdown | Complete guide to usage, settings, and troubleshooting

When reusing existing HTML in a README or article draft, parse tags as DOM rather than replacing text, and convert them to Markdown using rules for each element.

A flow for converting Markdown and HTML while checking Source and safe Preview separately
A flow for converting Markdown and HTML while checking Source and safe Preview separately

Convert Markdown and HTML in the browser

Review the Source of conversion results and a sanitized Preview separately without sending input to a server.

Convert HTML to Markdown

Conclusion: Parse HTML as a DOM and map meaningful elements to Markdown syntax

h1–h6, p, strong/em, ul/ol, blockquote, pre/code, a, img, table, and similar elements can be mapped to Markdown.

Class, style, and data attributes, layout divs, complex tables, and similar elements have no equivalent Markdown representation, so simplification or loss occurs.

Verify separately that conversion succeeded and that meaning, appearance, and safety are preserved at the destination.

Process with the DOM and conversion Rules rather than Tag replacement

Because string replacement can easily break nesting, attributes, entities, and whitespace, build a tree with DOMParser and transform by node type.

The current tool does not retrieve HTML from URLs. Use HTML source or a file, and remove authentication cookies and personal information before sharing.

Account to checkConfirmation detailsjudgment
Headingh1~h6Number of # characters
Listul/ol/liNested Indent
Codepre/codeFence length and language class
Link/Imagehref/srcBase URL

Steps for checking with a Markdown / HTML conversion tool

  1. Select HTML→Markdown, then paste HTML or open a File.
  2. Choose whether to retain, convert to Text, or remove unsupported elements.
  3. Enter a Base URL if you need to resolve relative URLs.
  4. Convert, then check the Markdown source and preview.

Do not include credentials or tokens in the base URL. The tool does not fetch URL destinations.

Mapping between HTML elements and Markdown

HTMLMarkdownInformation that may be lost
<h2>##id / class
<strong>** **style
<a href>[text](url)data attributes
<table>Pipe Tablerowspan and colspan

Check conversion, display, and sanitization as separate steps.

ProcessMain roleWhat is not guaranteed here
Parse/conversionMap Markdown syntax to HTML elements, or HTML DOM to Markdown notationCSS appearance and destination-specific extensions
SanitizeExclude script, iframe, form, event attributes, dangerous URLs, and similar content.Complete preservation of the original HTML and compliance with all business requirements
PreviewCheck sanitized results in an iframe isolated from the main applicationSame CSS as the production CMS and persistence of external resources
Save and pasteOutput the checked source to a file or the clipboardRe-sanitization and automatic formatting at the conversion destination

A setting that allows raw HTML in Markdown is not a setting that disables sanitization. Whether to accept raw HTML as syntax and whether to remove dangerous elements from generated HTML are independent decisions. Do not put untrusted input directly into innerHTML without processing; sanitize after conversion as well, and isolate it from executable previews.

Regression tests to check after conversion

  • Check headings, paragraphs, bold, italics, ordered, unordered, and nested lists, quotes, and horizontal rules
  • Check inline code, fenced code, backticks within fences, language declarations, and HTML pre/code
  • Check links, reference links, images, relative URLs, parentheses containing URLs, and title attributes
  • Verify GFM tables, task lists, strikethrough, and autolinks using the same dialect as the destination
  • Check Raw HTML, HTML Entities, &, <, >, two-space line breaks, blank lines, and Whitespace.
  • Check that script, onclick, javascript:, iframe, form, and similar content cannot execute in the Preview or saved result.
  • Compare the Markdown→HTML→Markdown round-trip diff and check for loss of meaning, attributes, whitespace, and expression formats

Supported scope of the current Markdown and HTML conversion tool

The current DevelopTools tool processes Markdown to HTML and HTML to Markdown only in the browser. Markdown to HTML uses Marked in GFM mode to convert headings, paragraphs, emphasis, lists, quotes, tables, task lists, strikethrough, code, links, and images. HTML to Markdown serializes DOM parsed by DOMParser using its own per-tag rules, converting headings, paragraphs, emphasis, lists, quotes, tables, pre/code, links, images, and more.

FunctionCurrent tool operation
InputPaste Text, load Markdown / HTML Files, Drag & Drop
Markdown dialectMarked GFM mode. Optionally switch the option that converts line breaks to br
HTML outputHTML fragment or complete document, formatted or minified to one line
HTML→MarkdownCustom converter. Choose whether to preserve, convert to text, or remove unsupported elements.
SafetySanitize conversion results with DOMPurify and preview in a sandbox iframe with CSP
External communicationConversion itself sends nothing. A request is made to the image host only when an external image preview is explicitly enabled.
UnsupportedFetching Web Pages from URLs, CSS reproduction, obtaining the DOM after JavaScript execution, complete round-trip restoration, Front Matter-specific parsing

The converted source and preview are different things. Check the source intended for saving or pasting, then check the structure in the sanitized preview. Also verify final CSS appearance, CMS-specific sanitizers, relative URL bases, and the Markdown dialect adopted by the destination at the destination itself.

Check the specification and the library's official documentation

Markdown implementations differ, so check syntax expectations against CommonMark, GFM extensions against GitHub Flavored Markdown, and options for the parser in use against its official documentation. Marked officially states that it does not sanitize output HTML, so treat sanitization after conversion as a separate step. Turndown is reference material for understanding rules, keep, remove, and GFM plugin concepts as a representative HTML→Markdown implementation; the current tool itself does not use Turndown.

Example: convert CMS body HTML back to a Markdown draft

Enter an HTML fragment that includes h2, p, ul, pre/code, and a in the body.

It can be converted to Markdown for easier re-editing, but CMS-specific classes must be recorded separately.

  1. Extract HTML
  2. Unsupported element settings
  3. conversion
  4. Check Source differences.

The current tool is a custom converter and does not use Turndown.

Frequently asked questions

Can Markdown→HTML→Markdown return perfectly to the original text?
It cannot be fully restored. The same meaning can be expressed by multiple Markdown syntaxes, and Markdown has no equivalent representation for HTML class, style, data attributes, complex tables, or whitespace. Always check differences after a round trip.
If Raw HTML is allowed, can scripts also be saved?
The current Tool cannot save it. Separately from Raw HTML interpretation settings, DOMPurify removes script, iframe, form, event attributes, and more, and the Preview also uses CSP.
Is the input content sent to a server?
Conversion, File reading, Copy, and Download are completed in the browser. However, when external image Preview is enabled, the browser requests the image URL's Host.