Convert Figma logo to code with AI

markedjs logomarked

A markdown parser and compiler. Built for speed.

32,981
3,387
32,981
17

Top Related Projects

CommonMark parser and renderer in JavaScript

14,258

A bidirectional Markdown to HTML to Markdown converter written in Javascript

Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed

Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.

32,991

A markdown parser and compiler. Built for speed.

A Markdown parser for javascript

Quick Overview

Marked is a fast and lightweight JavaScript markdown parser and compiler. It's designed to be easy to use and extend, making it suitable for a wide range of applications, from simple markdown rendering to complex content management systems.

Pros

  • Fast and efficient parsing and rendering of markdown
  • Highly extensible with support for custom renderers and extensions
  • Well-maintained with regular updates and bug fixes
  • Supports both browser and Node.js environments

Cons

  • Limited built-in support for some advanced markdown features
  • Documentation can be sparse for more advanced use cases
  • Some security concerns if not properly configured when parsing untrusted input
  • Performance can degrade with very large markdown documents

Code Examples

  1. Basic usage:
import { marked } from 'marked';

const markdown = '# Hello, world!\n\nThis is **bold** text.';
const html = marked(markdown);
console.log(html);
  1. Custom renderer:
import { marked } from 'marked';

const renderer = new marked.Renderer();
renderer.heading = (text, level) => {
  return `<h${level} class="custom-heading">${text}</h${level}>`;
};

const html = marked('# Custom Heading', { renderer });
console.log(html);
  1. Async parsing:
import { marked } from 'marked';

const markdown = '# Async Parsing\n\nThis is parsed asynchronously.';
marked.parse(markdown, (err, html) => {
  if (err) throw err;
  console.log(html);
});

Getting Started

To use Marked in your project, first install it via npm:

npm install marked

Then, in your JavaScript file:

import { marked } from 'marked';

const markdown = '# Hello, Marked!\n\nThis is a simple example.';
const html = marked(markdown);
console.log(html);

For more advanced usage and configuration options, refer to the Marked documentation.

Competitor Comparisons

CommonMark parser and renderer in JavaScript

Pros of commonmark.js

  • Strictly adheres to the CommonMark specification, ensuring consistent parsing across implementations
  • Provides a robust API for extending and customizing the parser
  • Offers better performance for large documents

Cons of commonmark.js

  • Less feature-rich compared to marked, focusing primarily on core Markdown syntax
  • Smaller community and ecosystem, potentially leading to fewer resources and extensions

Code Comparison

marked:

import { marked } from 'marked';

const html = marked('# Hello, world!');
console.log(html);

commonmark.js:

import { Parser, HtmlRenderer } from 'commonmark';

const parser = new Parser();
const renderer = new HtmlRenderer();
const ast = parser.parse('# Hello, world!');
const html = renderer.render(ast);
console.log(html);

Key Differences

  • marked offers a simpler API for basic usage, while commonmark.js provides more granular control over parsing and rendering
  • commonmark.js separates parsing and rendering steps, allowing for easier manipulation of the abstract syntax tree
  • marked includes built-in support for GFM (GitHub Flavored Markdown), while commonmark.js focuses on the core CommonMark specification

Use Cases

  • Choose marked for quick implementation and broader feature set
  • Opt for commonmark.js when strict CommonMark compliance and extensibility are priorities
14,258

A bidirectional Markdown to HTML to Markdown converter written in Javascript

Pros of Showdown

  • More flexible and customizable with a wider range of extension options
  • Better support for GitHub Flavored Markdown (GFM) out of the box
  • Easier to use in browser environments without additional setup

Cons of Showdown

  • Generally slower performance, especially for large documents
  • Less actively maintained compared to Marked
  • Larger bundle size, which may impact load times in web applications

Code Comparison

Marked usage:

const marked = require('marked');
const html = marked('# Hello, world!');

Showdown usage:

const showdown = require('showdown');
const converter = new showdown.Converter();
const html = converter.makeHtml('# Hello, world!');

Both libraries achieve similar results, but Showdown requires creating a converter instance before parsing Markdown. Marked offers a more straightforward API for basic usage, while Showdown provides more flexibility for advanced configurations.

Overall, Marked is often preferred for its performance and simplicity, while Showdown offers more customization options and better GFM support. The choice between the two depends on specific project requirements and the importance of factors like speed, extensibility, and ease of use.

Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed

Pros of markdown-it

  • More extensible and customizable through plugins
  • Better CommonMark compliance and stricter parsing
  • Faster performance, especially for larger documents

Cons of markdown-it

  • Slightly larger bundle size
  • Steeper learning curve for advanced customization
  • Less widespread adoption compared to marked

Code Comparison

marked:

import marked from 'marked';

const html = marked('# Hello, world!');
console.log(html);

markdown-it:

import MarkdownIt from 'markdown-it';

const md = new MarkdownIt();
const html = md.render('# Hello, world!');
console.log(html);

Both libraries offer simple APIs for basic Markdown parsing, but markdown-it provides more options for configuration and customization. The markdown-it approach allows for easier plugin integration and fine-tuning of parsing behavior.

marked is known for its simplicity and ease of use, making it a popular choice for quick implementations. However, markdown-it's extensibility and stricter parsing make it more suitable for complex projects or when adhering closely to CommonMark specifications is crucial.

Performance-wise, markdown-it generally outperforms marked, especially when dealing with larger documents. This can be a significant factor for applications processing substantial amounts of Markdown content.

Ultimately, the choice between these libraries depends on project requirements, desired customization level, and performance needs.

Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.

Pros of Remarkable

  • Faster parsing and rendering performance
  • More extensive configuration options and customization
  • Better support for CommonMark specification

Cons of Remarkable

  • Less active maintenance and updates
  • Smaller community and ecosystem
  • Fewer built-in extensions and plugins

Code Comparison

Marked:

import { marked } from 'marked';

const html = marked('# Hello, world!');
console.log(html);

Remarkable:

import { Remarkable } from 'remarkable';

const md = new Remarkable();
const html = md.render('# Hello, world!');
console.log(html);

Both Marked and Remarkable are popular Markdown parsers for JavaScript. Marked is known for its simplicity and ease of use, while Remarkable offers more advanced features and customization options.

Remarkable provides better performance, especially for larger documents, and adheres more closely to the CommonMark specification. It also offers more extensive configuration options, allowing developers to fine-tune the parsing and rendering process.

However, Marked has a larger and more active community, which translates to more frequent updates, better documentation, and a wider range of third-party extensions. It's also generally easier to get started with and integrate into existing projects.

In terms of usage, both libraries have similar APIs, but Remarkable requires instantiation of a parser object before rendering, while Marked can be used directly as a function.

32,991

A markdown parser and compiler. Built for speed.

Pros of marked

  • Widely adopted and battle-tested Markdown parser
  • Extensive documentation and community support
  • Highly customizable with options and extensions

Cons of marked

  • Larger bundle size compared to some alternatives
  • May have slower parsing speed for very large documents

Code comparison

marked:

import { marked } from 'marked';

const markdown = '# Hello, world!';
const html = marked(markdown);
console.log(html);

marked:

import { marked } from 'marked';

const markdown = '# Hello, world!';
const html = marked(markdown);
console.log(html);

Summary

Both marked and marked are essentially the same project. The comparison above is between the current version of marked and itself. The repository markedjs/marked is the main project, while markedjs/marked> (with the ">" character) doesn't exist as a separate repository.

marked is a popular Markdown parser for JavaScript, known for its flexibility and extensive feature set. It's widely used in various projects and has a large community backing it. While it offers great functionality, users should be aware of potential performance considerations for very large documents or when bundle size is a critical factor.

For most use cases, marked provides an excellent balance of features, customization options, and ease of use for parsing Markdown in JavaScript applications.

A Markdown parser for javascript

Pros of markdown-js

  • More extensive configuration options for customizing parsing behavior
  • Supports a wider range of Markdown flavors and extensions
  • Better suited for server-side rendering and Node.js environments

Cons of markdown-js

  • Less actively maintained, with fewer recent updates
  • Slower parsing performance, especially for large documents
  • Limited browser support compared to marked

Code Comparison

markdown-js:

var markdown = require( "markdown" ).markdown;
console.log(markdown.toHTML("Hello *World*!"));

marked:

const marked = require('marked');
console.log(marked('Hello *World*!'));

Both libraries provide simple APIs for converting Markdown to HTML, but marked offers a more streamlined approach with fewer configuration steps required for basic usage.

marked is generally considered faster and more lightweight, making it a popular choice for browser-based applications. It also has better documentation and more frequent updates.

markdown-js, on the other hand, offers more flexibility in terms of parsing options and support for various Markdown dialects. It may be preferred in scenarios where extensive customization of the Markdown parsing process is required.

Ultimately, the choice between these libraries depends on specific project requirements, performance needs, and the target environment (browser vs. server-side).

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Marked

npm gzip size install size downloads github actions snyk

  • ⚡ built for speed
  • ⬇️ low-level compiler for parsing markdown without caching or blocking for long periods of time
  • ⚖️ light-weight while implementing all markdown features from the supported flavors & specifications
  • 🌐 works in a browser, on a server, or from a command line interface (CLI)

Demo

Checkout the demo page to see marked in action ⛹️

Docs

Our documentation pages are also rendered using marked 💯

Also read about:

Compatibility

Node.js: Only current and LTS Node.js versions are supported. End of life Node.js versions may become incompatible with Marked at any point in time.

Browser: Not IE11 :)

Installation

CLI:

npm install -g marked

In-browser:

npm install marked

Usage

Warning: 🚨 Marked does not sanitize the output HTML. Please use a sanitize library, like DOMPurify (recommended), sanitize-html or insane on the output HTML! 🚨

DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('not happening')">`));

CLI

# Example with stdin input
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
# Print all options
$ marked --help

Browser

<!doctype html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>Marked in the browser</title>
</head>
<body>
  <div id="content"></div>
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  <script>
    document.getElementById('content').innerHTML =
      marked.parse('# Marked in the browser\n\nRendered by **marked**.');
  </script>
</body>
</html>

or import esm module

<script type="module">
  import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
  document.getElementById('content').innerHTML =
    marked.parse('# Marked in the browser\n\nRendered by **marked**.');
</script>

License

Copyright (c) 2011-2022, Christopher Jeffrey. (MIT License)

NPM DownloadsLast 30 Days