Commit Graph
315 Commits
Author SHA1 Message Date
Hashim Khan b8cf7dc592 fix: place task checkboxes after list loose is finalized (#4046)
Loose nested task lists could leave checkboxes outside <p> because
checkbox placement used list.loose before spacer detection finished.
Compute the final loose state first, then place checkboxes.

Fixes #4045
2026-08-15 12:57:45 -06:00
Jayesh BhadeandJayesh 681373ccc0 fix: keep the em/strong mask the same length as the source (#4044)
emStrong and del align maskedSrc with src by slicing the mask from the
end, so every mask must keep the length of the text it replaces. The
escape mask substituted a fixed two-character '++', but anyPunctuation is
/\\([\p{P}\p{S}])/gu and matches astral code points, so an escaped
character above U+FFFF is three code units masked as two.

The mask then ended up shorter than the source, the clip reached one code
unit too far back, and the resulting match.index was applied to src: the
closing delimiter was consumed a code unit late, leaving a stray
delimiter inside the emphasis and, for some inputs, dropping a character
of the document.

Substitute one '+' per code unit instead. '+' is punctuation, so the
delimiter flanking of the masked region is unchanged, and the ASCII case
still produces '++'.

Co-authored-by: Jayesh <jayesh.bhade@keychain.com>
2026-08-05 08:51:04 -06:00
deepakganesh78andCopilot 81bd750533 fix: parse EOF backtick fences after paragraphs (#4039)
* fix: parse EOF backtick fences after paragraphs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: handle EOF tilde fence interruption

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-04 22:18:30 -06:00
Columbus Labs 641e5df935 docs: explain partial extensions in use (#4033) 2026-08-03 22:32:04 -06:00
spokodev 452f1ed6a7 fix: Fix spurious deeper nesting in a blockquote continuation (#4030) 2026-08-03 22:31:16 -06:00
spokodev e8544e6a67 fix: an unmatched strong run before emphasis stays literal (#4008) 2026-08-03 22:30:17 -06:00
Waiter 823093f3d4 fix: pedantic **foo:** and **"word"** emphasis parsing (#3999) 2026-08-03 22:29:40 -06:00
Sarath Francis e1b6139fec fix: fall back to default checkbox renderer when extension returns false (#4023)
A renderer extension named after a built-in token can return false to
fall back to the default renderer. The Parser decides that from a list
of built-in token type names, and 'checkbox' was never added to either
the block or the inline list when the checkbox token was introduced.

The result is that a `checkbox` renderer extension returning false
emits nothing instead of falling back, so the checkbox silently
disappears from the task item.
2026-07-23 22:37:40 -06:00
Anh Hong 9154f8f3cb fix: Avoid O(n^2) masked source rebuild in inline tokenizer (#4017) 2026-07-14 21:05:11 -06:00
Anh Hong f945fc5e10 fix: Avoid O(n^2) backtracking in HTML block close and tilde interrupt regexes (#4014)
* fix: Avoid O(n^2) backtracking in HTML block close regex

The close branches end in `[^\n]*\n+`; the trailing `\n+` requires a
newline, so at EOF the close can't match and the engine retries every
split of the lazy `[\s\S]*?` before falling through to `$`, which is
O(n^2). `\n*` closes on first match and consumes identical text whenever
a trailing newline is present (the `[^\n]*` was added in #3991).

* fix: Avoid O(n^2) backtracking in tilde paragraph interrupt regex

The backtick branch is guarded by a lookahead but `~{3,}` isn't, and it
overlaps the following `[^\n]*`, so a long newline-less tilde run
backtracks quadratically. Since `~{3,}` is always followed by `[^\n]*`,
`~~~` matches the same strings without the overlap. The real fences
tokenizer is left untouched.
2026-07-14 16:08:51 -06:00
spokodev 3f144a0e93 fix: keep empty list after blockquote as a sibling block (#4004)
A blockquote followed by a bare list marker line (for example
`> foo\n-`) wrongly nested an empty list inside the blockquote.

The blockquote regex reuses the paragraph list-interrupt clause
` {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]`, whose trailing `[ \t]+[^ \t\n]`
requires content after the marker. A bare marker line therefore was
not seen as an interruption and got lazily continued into the
blockquote paragraph, then re-lexed into a nested empty list.

Give the blockquote its own paragraph variant whose list-interrupt
clause also matches a bare marker, so the list ends the blockquote and
becomes a sibling block. The top level paragraph rule is unchanged, so
an empty list still cannot interrupt a paragraph.
2026-07-14 16:08:05 -06:00
Luke Parker 0de7188bf1 fix: preserve code spans adjacent to tildes (#4012)
* fix: preserve code spans adjacent to tildes

* perf: isolate mixed delimiter boundaries

* refactor: keep delimiter boundaries in grammar
2026-07-14 16:07:23 -06:00
Anh Hong f056437b38 fix: Recognize setext headings whose first line starts with # (#4015)
A line like `#1 Goals` or `#hashtag` followed by a setext underline was
rendered as a paragraph plus `<hr>` instead of a heading. A line only
starts an ATX heading when the `#`s are followed by whitespace or EOL, so
these are paragraph text and the underline makes a setext heading. The
lheading ATX-interrupt check was bare ` {0,3}#{1,6}`, missing the
`(?:\s|$)` that the paragraph and ATX heading rules already require.
2026-07-14 16:06:36 -06:00
Sarath Francis bc2f121456 fix: treat a line of only tabs as a blank line between paragraphs (#4007) 2026-07-13 21:07:06 -06:00
Anh Hong a0098085f4 fix: Avoid O(n^2) backtracking in inline link href regex (#4013) 2026-07-09 11:04:39 -06:00
Rayan Salhab 33928d0663 fix: Fix ordered lists after blockquotes (#4003) 2026-06-29 22:23:30 -06:00
Sarath Francis bbb84c88cf fix: keep trailing text on HTML block close line for PI, declarations, and CDATA (#3991) 2026-06-29 22:22:43 -06:00
Sarath Francis b55410f846 fix: parse empty list item with trailing space (#3984)
A bare list marker followed only by a space (e.g. `- ` or `1. `) was not
recognized as a list and fell through to a paragraph, so `- ` rendered as
`<p>- </p>` instead of an empty list item. A marker with no trailing space
(`-`, `1.`) and an empty item that continues an existing list were already
handled correctly, making the behavior inconsistent.

The block `list` rule required content after the marker's whitespace
(`[ \t][^\n]+?`), so a marker followed only by whitespace failed to match.
Relax it to `[ \t][^\n]*?` so a marker with trailing whitespace and no
content still starts a list, matching the CommonMark reference and
markdown-it.

To keep CommonMark's rule that an empty list item cannot interrupt a
paragraph, the paragraph list-interrupt patterns now require a non-blank
character after the marker, so `foo\n+ ` stays a single paragraph while
`foo\n- bar` still interrupts.
2026-06-04 08:11:58 -06:00
a37983f188 fix: cache list indentation regexes (#3969)
* Cache list indentation regexes

* Handle zero indent in cached regexes

* Update src/rules.ts

Co-authored-by: Steven <steven@ceriously.com>

---------

Co-authored-by: Tony Brix <tony@brix.ninja>
Co-authored-by: Steven <steven@ceriously.com>
2026-05-18 23:13:54 -06:00
Hafez 2608e810c0 fix: avoid task checkbox for setext heading text (#3960)
* test: cover task marker before setext heading

* fix: avoid task checkbox for setext heading text

* test: cover loose setext task candidate

* fix: preserve loose list detection for demoted tasks

* test: move setext task output coverage to specs
2026-05-01 08:18:12 -06:00
Tony Brix 58a52e8a49 fix: fix infinite loop for indented code blank line (#3947)
* fix: fix infinite loop for indented code blank line

* set redos tests to not silent

* simplify test

* fix test
2026-04-18 07:06:46 -06:00
christophe geiser abd907aab5 fix(rules): ensure lookbehind regex is evaluated correctly by minifiers (#3945)
* fix(rules): ensure lookbehind regex is evaluated correctly by minifiers

* Use a default variable in the regex to prevent removal by minifiers

* fix(rules): remove unnecessary eslint directive for lookbehind regex
2026-04-16 21:11:49 -06:00
Tony Brix b70895f47b fix: trim blank lines from block tokens (#3939)
BREAKING CHANGE: trim trailing blank lines from block tokens
2026-04-06 23:32:53 -06:00
Pushkar GuptaandPushkar Gupta 40f266560a fix: prevent GFM table tokens from greedily capturing trailing newlines (#3926)
Co-authored-by: Pushkar Gupta <your_email@example.com>
2026-04-06 22:14:37 -06:00
Pushkar Gupta b379e3e571 fix: prevent heading and def tokens from greedily capturing multiple newlines (#3925) 2026-04-06 22:12:50 -06:00
Jerry Chen 6e96fa7bbc fix: avoid race condition in async parallel parse/parseInline with hooks (#3924) 2026-04-05 00:01:25 -06:00
Ankit Singh 3b59e81a1b refactor: use strict equality in RegExp exec checks (#3935) 2026-04-03 21:52:43 -06:00
Sam.An c732dd2221 fix: prevent quadratic complexity in emStrongLDelim regex (#3906) 2026-03-20 09:07:53 -06:00
Veer Shah f3a3ec05cb fix: re-assign tokenizer.lexer and renderer.parser at start of each parse call (#3907) 2026-03-20 09:07:37 -06:00
CopilotandUziTech 4625980454 fix: Fix catastrophic backtracking (ReDoS) in link/reflink label regex (#3918)
Co-authored-by: UziTech <97994+UziTech@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-03-20 09:07:11 -06:00
5e03369db4 fix: prevent single-tilde strikethrough false positives (#3910)
Co-authored-by: Nikita Barinov <diadorer@nebius.com>
Co-authored-by: Tony Brix <tony@brix.ninja>
2026-03-20 09:06:48 -06:00
Veer Shah 3ea7e88e15 fix: trim trailing whitespace from lheading text (#3920) 2026-03-20 09:06:07 -06:00
Tzong Hao Chen 46fb9b806f fix: prevent ReDoS in inline link regex title group (#3902)
The title separator in the link regex used [ \t]* which allowed the
title group to be probed at every backtrack position of the greedy href
group. On long single-line input containing [text]( patterns without a
nearby closing ), this produced O(n²) per regex call and O(n³) in the
full inline tokenizer.

Change [ \t]* to [ \t]+|\n to require actual whitespace before the
title. This matches CommonMark spec requirements and eliminates the
backtracking cascade.

Before: 18K input takes ~36 seconds (event loop blocked)
After:  18K input takes ~45ms
2026-03-04 08:30:23 -07:00
Tony Brix 8045055664 chore: rename escape helper function (#3900)
* chore: update helpers

* fix image alt escape

* remove unescapeTest regex
2026-02-18 09:12:09 -07:00
Tony Brix 909fe442aa fix: escape image alt text (#3896) 2026-02-17 13:03:25 -07:00
Tony Brix e0311759cd fix: fix list item wrong indent (#3889) 2026-02-11 09:39:56 -07:00
Tony Brix 9fc4f8e4a8 fix: fix list with tabs (#3891) 2026-02-11 09:39:30 -07:00
Tony Brix 3fc6a44ed5 fix: fix empty list item (#3890) 2026-02-11 09:39:01 -07:00
Tony Brix 2a475a1fb5 fix: fix blockquote after list (#3888) 2026-02-11 09:38:30 -07:00
Tony Brix 1a5b124c0c fix: fix strikethrough flanking rules (#3882) 2026-02-11 09:37:41 -07:00
Tony BrixandSteven 921ee22102 fix: fix block elements in task item (#3828)
Co-authored-by: Steven <steven@ceriously.com>
2025-11-20 09:56:01 -07:00
dependabot[bot]andTony Brix 8a355d181b chore(deps-dev): Bump @markedjs/eslint-config from 1.0.13 to 1.0.14 (#3835)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony Brix <tony@brix.ninja>
2025-11-12 01:33:13 -07:00
Tony Brix 7b192315b2 fix: only create tokens inside tokenizers (#3755)
BREAKING CHANGE:
- Change how consecutive text tokens work in lists
- Simplify listItem renderer
- Checkbox token is added in list tokenizer
- Checkbox token add type and raw property
- Change loose list text tokens to paragraph type in the list tokenizer
2025-11-06 23:33:11 -07:00
Ziad El Khoury HannaandSteven c056df082c fix: Avoid RegExp lookbehind assertions (#3816) (#3817)
* fix: Avoid RegExp lookbehind assertions (#3816)

RegExp lookbehind assertions are supported in Safari >= 16.5, avoiding them
keeps support for older Safari versions.

* Improve perf of blockSkip on modern engines

RegExp lookbehind assertions are supported in Safari >= 16.5. But the
lookbehind-less version has a performance penalty. So having a fallback keeps
support for older Safari versions while maintaining performance for modern
engines.

* Add comment about lookbehind browser support

As suggested by @styfle

Co-authored-by: Steven <steven@ceriously.com>

---------

Co-authored-by: Steven <steven@ceriously.com>
2025-11-06 15:23:37 -07:00
Tony Brix f9fa5bb70b chore: clean up blockskip (#3801) 2025-10-17 01:21:06 -06:00
Sankalp TripathiandTony Brix 1da8fb5da9 fix: resolve even-numbered backtick precedence issue (#3776) (#3786)
Co-authored-by: Tony Brix <tony@brix.ninja>
2025-10-17 01:05:03 -06:00
Tony Brix 7b4c5208d1 chore: clean up rules (#3791) 2025-10-06 21:29:33 -06:00
Tony Brix 09577e569b feat: Add async provideParser provideLexer (#3756) 2025-10-06 21:22:04 -06:00
Awraam 626d961335 fix: Make www case-sensitive when detecting link starts (#3770) 2025-10-06 21:21:10 -06:00
Lakshyajeet Singh Goyal e3c0d3e208 fix: fix links with square brackets in inline code break wrapping italics (#3785) 2025-10-06 21:19:22 -06:00