# Marked — Fast Markdown Parser and Compiler for JavaScript > A low-level markdown compiler built for speed that parses markdown into HTML with full CommonMark and GFM support. ## Install Save in your project root: # Marked — Fast Markdown Parser and Compiler for JavaScript ## Quick Use ```bash npm install marked ``` ```js import { marked } from 'marked'; const html = marked.parse('# Hello World Some **bold** text.'); ``` ## Introduction Marked is a markdown parser and compiler built for speed. It converts markdown text into HTML in both Node.js and browser environments, supporting CommonMark, GitHub Flavored Markdown, and custom extensions without relying on native dependencies. ## What Marked Does - Parses markdown strings into HTML output with configurable options - Supports CommonMark spec, GFM tables, task lists, and strikethrough - Provides synchronous and asynchronous parsing modes - Allows custom renderers to override how each markdown token produces HTML - Offers a tokenizer API for programmatic access to the parsed AST ## Architecture Overview Marked processes markdown in three stages: the Lexer tokenizes raw markdown into a flat token list, the Parser walks the tokens and calls Renderer methods, and the Renderer outputs HTML strings. Each stage is replaceable. Custom extensions can add new token types by hooking into the lexer and providing matching renderer logic. The design keeps the core single-file and dependency-free. ## Installation & Configuration - Install via npm or load the UMD bundle from a CDN for browser use - Call marked.parse() with a markdown string and an options object - Enable GFM mode, smart quotes, or header ID generation via options - Register custom extensions with marked.use() for new syntax rules - Works in Node.js, Deno, Bun, and all modern browsers ## Key Features - One of the fastest pure-JS markdown parsers available - Extensible tokenizer and renderer for custom markdown syntax - Zero dependencies and works in any JavaScript runtime - Async mode for safely processing untrusted input with sanitization - Compatible with highlight.js and Prism for fenced code block syntax highlighting ## Comparison with Similar Tools - **markdown-it** — plugin-based with more built-in extensions; Marked is faster for standard parsing - **remark (unified)** — AST-based ecosystem for transforms and linting; Marked is simpler for parse-to-HTML - **Showdown** — similar feature set but slower benchmarks; Marked optimizes for throughput - **Commonmark.js** — strict CommonMark reference implementation; Marked adds GFM and extension support - **MDX** — compiles markdown with JSX components; Marked focuses on plain markdown to HTML ## FAQ **Q: Does Marked sanitize HTML output?** A: Marked does not sanitize by default. Use a library like DOMPurify on the output if processing untrusted input. **Q: Can I add custom markdown syntax?** A: Yes. Use marked.use() with a custom extension that defines tokenizer and renderer functions for your new syntax. **Q: Does Marked support syntax highlighting in code blocks?** A: Marked provides a highlight option where you pass a function that receives code and language, letting you integrate any highlighter. **Q: How does Marked handle GFM tables?** A: GFM mode is enabled by default. Tables with pipes and header separators render to HTML table elements automatically. ## Sources - https://github.com/markedjs/marked - https://marked.js.org --- Source: https://tokrepo.com/en/workflows/c0362435-3ffa-11f1-9bc6-00163e2b0d79 Author: AI Open Source