By Docify

Convert Markdown to HTML: marked + DOMPurify

• 5 min read

Convert Markdown to HTML using marked.js with GitHub Flavored Markdown support. The result is sanitized with DOMPurify to prevent XSS. Features include tables, task lists, fenced code blocks, and inline formatting. All conversion runs locally in your browser. Try the live converter.

README files and notes are easier to write in Markdown, but websites expect HTML. You do not need a server for a common subset: the browser can parse the text locally. The steps below use that path, then point at the live Markdown converter.

How to convert Markdown to HTML in three steps

Step 1: Paste the Markdown

Type or paste into the left-hand box. There is no .md file upload. Try it with the live converter with the string below. Headings, lists, links, emphasis, fenced code, and the blockquote all render through marked.

## Welcome to Markdown

This is a **bold text** and this is *italic text*.

### Features

- Easy to write
- Easy to read
- Converts to HTML

### Code Example

```javascript
function hello() {
  console.log("Hello, World!");
}
```

#### Links

Visit [Docify](https://example.com) for more tools.

> This is a blockquote.

Step 2: Check the sanitized preview

Open the Docify Markdown converter. Each keystroke runs marked() then DOMPurify.sanitize(). The right-hand pane shows that HTML. The page does not upload the text.

Step 3: Copy or download the fragment

Copy HTML writes the sanitized string to the clipboard. Download HTML saves it as converted.html (text/html). That file is a fragment — no doctype, head, or preview CSS. Copy example HTML is the sanitized output below. marked writes " inside the fence; the sanitized fragment uses ". Headings stay bare — marked v11 defaults do not add header ids.

<h2>Welcome to Markdown</h2>
<p>This is a <strong>bold text</strong> and this is <em>italic text</em>.</p>
<h3>Features</h3>
<ul>
<li>Easy to write</li>
<li>Easy to read</li>
<li>Converts to HTML</li>
</ul>
<h3>Code Example</h3>
<pre><code class="language-javascript">function hello() {
  console.log("Hello, World!");
}
</code></pre>
<h4>Links</h4>
<p>Visit <a href="https://example.com">Docify</a> for more tools.</p>
<blockquote>
<p>This is a blockquote.</p>
</blockquote>

What the converter actually emits

Parser

The page uses marked v11 with that library's default parser (GitHub-flavored Markdown options on). Exact edge cases follow marked, not a custom spec. GFM table output of | Name | Count | then | --- | --- | then | Ada | 2 | is a <table>. The preview is not a syntax-highlighted editor.

Sanitizer

DOMPurify strips unsafe tags and attributes before preview, copy, or HTML download. Typical headings, lists, links, GFM tables, and images that marked emits are kept when they are safe. Alignment output of :--- / :---: / ---: keeps align="left", align="center", and align="right". The tool does not fetch or host image files for you.

PDF is a separate path

Download PDF does not render this HTML. It walks Markdown lines, strips heading hashes, emphasis, and link URLs, then draws output text with jsPDF. The PDF demo outputs: Welcome to Markdown; This is a bold text and this is italic text.; the three - list lines stay; ```javascript and the hello() lines stay; Visit Docify for more tools. (https://example.com dropped); > This is a blockquote. stays. See the Markdown-to-PDF guide for the strip rules.

Common Markdown that marked maps to HTML

Headings

Markdown:

# H1
## H2
### H3

Typical HTML:

<h1>H1</h1>
<h2>H2</h2>
<h3>H3</h3>

Emphasis

Markdown:

**bold**
*italic*

Typical HTML:

<strong>bold</strong>
<em>italic</em>

GFM tables

Markdown input:

| Name | Count |
| --- | --- |
| Ada | 2 |

Sanitized output:

<table>…<th>Name</th><th>Count</th>…<td>Ada</td><td>2</td>

Links

Markdown:

[Docify](https://www.docify.me/)

Typical HTML:

<a href="https://www.docify.me/">Docify</a>

Convert Markdown in the browser

marked then DOMPurify.sanitize. Copy or download the HTML fragment. Nothing is uploaded.

Use Markdown Converter →

FAQ

Does this tool upload my markdown?
No. All conversion runs in your browser using marked.js. Your text is never sent to a server.
Is the HTML output sanitized?
Yes. The HTML is sanitized with DOMPurify to remove potentially dangerous elements and scripts.
Does it support GitHub Flavored Markdown?
Yes. Tables, task lists, strikethrough, and other GFM extensions are supported.
Can I copy or download the HTML?
Yes. Use the Copy button to copy to clipboard or Download to save as an HTML file.

Related