vidigoatandClaude Opus 5.5 e4ab77f6e4 feat: add lastToken to lexer state (#4160)
* 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>
2026-11-09 15:39:58 -07:00
2026-10-31 12:34:33 -06:00
2018-04-05 11:36:07 -04:00
2021-11-02 09:40:27 -05:00
2026-11-02 17:59:13 +00:00
2023-08-09 23:33:46 -06:00
2020-08-29 17:55:07 -04:00

Marked

npm install size downloads github actions snyk inspect.software

  • ⚡ 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

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)

S
Description
Lustro github.com/markedjs/marked
Readme Multiple Licenses
22 MiB
Languages
TypeScript 37.1%
JavaScript 36.6%
HTML 26.3%