mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
e4ab77f6e46d478cfed8697c308dddc60b9ddf99
* fix: only let a non-empty list starting with 1 interrupt a paragraph in a list item Inside a list item, paragraph lines are lexed as text tokens, and the list tokenizer ran before the text tokenizer without checking whether the list may interrupt the paragraph, so `14.` or an empty `*` on the next line started a nested list. Apply the same rule as the paragraph interrupt: only a non-empty list starting with a bullet or 1 can interrupt a paragraph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: move the list interrupt check into the list tokenizer The lexer passes its tokens to `list(src, tokens)`, and the tokenizer checks the last one, so `list(src)` overrides keep working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: keep the block tokens in the lexer state for the list tokenizer `blockTokens` sets `this.lexer.state.tokens` to the tokens it is lexing and restores the outer ones when it returns, so `list(src)` keeps its signature and checks the token before it from the state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: keep only the last block token in the lexer state `blockTokens` records the last token of the run it is lexing in `this.lexer.state.lastToken` before each tokenizer runs, and restores the outer one when a nested call returns, so the list tokenizer checks `state.lastToken` instead of the whole token list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Marked
- ⚡ 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
- 🛠️ easily adaptable with custom extensions
- 🌐 works in a browser, on a server, or from a command line interface (CLI)
Demo
Check out 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: Baseline Widely Available
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
Node.js
import { marked } from 'marked';
const html = marked.parse('# Marked in Node.js');
console.log(html);
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/lib/marked.umd.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) 2018+, MarkedJS. (MIT License) Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
Languages
TypeScript
37.1%
JavaScript
36.6%
HTML
26.3%