mirror of
https://github.com/markedjs/marked.git
synced 2026-12-01 16:56:16 +01:00
eab1e483fe88e559288d3003d493bbc0ec4ecf53
* fix: avoid quadratic scan for unmatched emphasis delimiters Tokenizer.emStrong and del walked every later delimiter for each unmatched opener, so parse time grew ~4x when those inputs doubled. Cache the last possible closer on maskedSrc and skip the scan when none remains after the opener. Fixes #4099 Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com> * fix: keep emphasis closer hints on the inline pass Address review on the unmatched-delimiter scan: remove the timing unit tests, cover mid-run openers in test/specs/new, name the emphasis and strikethrough closer indexes, and drop the module-level maskedSrc cache. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com> * refactor: scan unmatched emphasis closers in internal helpers Tokenizer no longer gains public methods. The last-closer scan still runs once per inline pass and the hint stack is dropped when that pass ends, so the masked source is not retained. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com> --------- Co-authored-by: David <244863912+dyk1454683243-sudo@users.noreply.github.com> Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.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.9%
JavaScript
36.5%
HTML
25.6%