跪拜 Guibai
← Back to the summary

Markdown vs. Marked: One Is a Language, One Is a Parser—Here's How to Use Both

In front-end development, we often encounter Markdown and Marked. Their names are similar, but they are not the same kind of thing, nor are they mutually exclusive options.

Simply put:

Markdown is a lightweight markup language; Marked is a JavaScript library for parsing Markdown.

Understanding this makes it clear that they are usually not an "either/or" choice, but rather used together.

What is Markdown?

Markdown is a syntax for writing text content using simple symbols. It can represent headings, lists, links, code blocks, and other structures, and is commonly used in READMEs, technical documentation, blogs, and comment content.

For example:

        
# Page Title

This is a paragraph containing **bold content**.

- First item
- Second item

[Visit example site](https://example.com)
        
      

Markdown files typically use the .md or .markdown extension. Its focus is on how content is written and organized, not on which programming language handles it.

What is Marked?

Marked is a JavaScript Markdown parser. It can read Markdown text and convert it to HTML.

        
import { marked } from 'marked';

const source = '# Page Title\n\nThis is **bold content**.';
const html = marked.parse(source);

console.log(html);
        
      

The output is roughly as follows:

        
<h1>Page Title</h1>
<p>This is <strong>bold content</strong>.</p>
        
      

Marked focuses on how to parse Markdown in a JavaScript project. It is often used in websites, web applications, or Node.js services.

Core Differences

Comparison Item Markdown Marked
Nature A lightweight markup language JavaScript parsing library
Purpose Write and organize content Convert Markdown to HTML
Depends on a programming language No Yes, mainly for JavaScript environments
Common form .md files or Markdown text npm package
Can replace each other No No

An analogy:

How to choose in real development?

Use Markdown when you need to write content

If you need to write project descriptions, technical documentation, blog posts, or knowledge base content, just use Markdown directly. It is easy to read, easy to write, and convenient for version control.

Choose Marked when you need to parse Markdown in JavaScript

If your project needs to convert Markdown content to HTML, for example:

Then you can use a parser like Marked.

They are usually used together

A common workflow:

        
Markdown text → Marked parsing → HTML → Page display
        
      

That is, content is written in Markdown, and then Marked converts it to HTML that the page can display.

Security considerations when using Marked

Marked parses Markdown, but do not assume it filters all unsafe HTML by default. If the Markdown content comes from user input, the converted HTML may contain malicious tags or scripts.

It is recommended to use an HTML sanitizer such as DOMPurify before inserting into the page:

        
import { marked } from 'marked';
import DOMPurify from 'dompurify';

const markdown = '# Article Title\n\nThis is some content.';
const html = marked.parse(markdown);
const safeHtml = DOMPurify.sanitize(html);

// Display safeHtml in a framework template; the specific method depends on the framework
        
      

Whether sanitization is needed depends on the source of the content and how it is displayed. For user-submitted content, security handling is usually necessary.

Summary

Markdown and Marked are not two products of the same kind:

Therefore, you don't need to choose between them: use Markdown when writing documents or articles; consider Marked when you need to parse that content in a JavaScript project.

Comments

Top 1 of 3 from juejin.cn, machine-translated. The original thread is authoritative.

卷土的土

Parsing and sanitization should be handled separately.

excel

What do you mean? Both can parse, markd uses a bit less memory.

excel

It's markdown.js that takes up a lot of memory.