Revert PR #4484 (merge b9bdd062c8f), retaining later Windows-path and GFM changes. Its display-dollar rules are replaced by upstream math parsing with bounded invalid-block recovery in the next commit.
A `$$` right after `\verb` or `\verb*` is that command delimiter, so it no
longer closes the block: `$$\n\verb$$\nx\n$$` keeps the whole formula and the
paragraph after it, as the grammar this replaced did. The tokenizer also drops
a dead null guard and the blank line the earlier removal left behind.
Tests cover the two delimiter spellings, a failed fence inside a comment, and
a trailing lone dollar; coverage stays at 100% on both changed files.
The `\verb` state machine added for a `%` inside verbatim regions produced its
own defect class: its lookahead rescanned the line for every unterminated
candidate (58 KB of them took ~2 s), a `%` taken as a candidate delimiter lost
its comment state on the fallback, and control words, bare letters, and the
starred delimiter each needed a rule. It is gone; the comment gate alone keeps
`$$\verb|%|$$` and the rest of a 17-case parity set at base behavior.
What replaces it is the single-line rule the flow needs anyway: a `$$` that
failed to close continues scanning while it is still on the opening line, so a
later `$$` there still closes (`$$\verb*a$$a$$`), and it ends the candidate at
that line's ending (or immediately, on a later line), so `$$x$$ trailing` and
the repeated-candidate inputs keep the behavior earlier rounds pinned.
Net: 12 fewer branches in the tokenizer, linear parser work, and 132 tests with
100% statements, branches, functions, and lines.
A comment whose text before the closing fence is empty or whitespace
(`95%$$`, `95 %$$`) no longer suppresses it, so a multi-line block whose last
line ends that way keeps its whole formula instead of falling back to upstream
and dropping its first line. A comment holding a non-whitespace character still
suppresses the fence, which keeps `\frac{1}{ % keep $$` at base behavior.
The note records the whitespace rule and its one consequence: a fence behind a
whitespace-only comment closes there, leaving a following lone `$$` as its own
empty block.
A `%` inside an already open comment is comment text, so it no longer resets
the comment's content flag: `$$\n% 100%$$\n$$` and a formula whose comment
holds `95%` before the fence keep scanning instead of closing one line early,
which restores base behavior for both.
The starred `\verb*` form repeats any character, letters included, so only the
plain form continues to reject a letter delimiter (`\verbatim`); `$$\verb*a$$a$$`
renders as base does. The Agent Note records the comment gate as a sixth
residual shape and lists the conditions the new cases pin.
A `%` whose comment text is empty (`95%$$`, or a multiline block whose last
line ends that way) no longer suppresses the closing fence, so the whole
formula survives instead of falling back to upstream and dropping its first
line. A `%` with text before the fence still suppresses it, which keeps
`\frac{1}{ % keep $$` and the no-space spelling at base behavior.
The verbatim scan now follows LaTeX's own reader: a letter cannot be the
delimiter, one `*` marks the starred form, the region must close before the
line ending or its characters stay ordinary content, and a comment holds no
commands. The Agent Note states which state belongs to which construct.
A bare `%` before a same-line closing fence (`$$\text{acc} = 95%$$`) stopped the
block from closing, so a display formula degraded to inline math. The comment
exception now applies only to a closing fence on a later line of the block,
which is where a multi-line block can hide one; a block that opens and closes
on one line keeps closing where it did before this flow spanned lines.
`\verb|%|` keeps its content reading, and the two comment cases are one test
with the annotation assertion on the first source only.
`\verb|%|` inside a display formula made the comment tracking treat the `%` as
a TeX comment, so the block skipped its closing `$$`, swallowed the following
paragraph into a KaTeX error, and split the next formula. KaTeX renders
`\verb`, so this was a regression against base.
The value scanner now recognizes the `\verb` prefix and consumes its region
without touching the comment or escape state: `$$\verb|%|$$` closes where base
closes. The note records the verbatim rule and drops the numeric case counts
the earlier revision stated.
An unescaped `%` inside a multi-line formula starts a TeX comment that runs to
the line ending, but the closing-fence check read a `$$` at the end of one as a
fence: `$$\n\frac{1}{ % keep $$\n2}\n$$` closed after the comment, produced a
KaTeX error for the truncated formula, and swallowed the paragraph after it
into a second block. The block now tracks the comment and ignores a fence
inside it, so base and this branch render the same value and keep the
following paragraph.
The Agent Note records the comment rule, states that every multi-line block
this flow owns is new (not only the ones on their own paragraph), and lists
the comment guard with the other seven.
A candidate line ending in an odd backslash kept the escape run alive across
the line ending and any blank lines after it, so the next line's leading `$$`
counted as escaped content and bypassed the closing-fence check. Base kept the
later block as its own display formula; this branch swallowed it into one
KaTeX error block, and repeating the pair made the parse quadratic (12.8 KB
took 1.4 s, 25.6 KB took 8.2 s).
The escape run now ends where the line ending is consumed, which is what a
trailing backslash escapes. The pair parses as base does and repeated
candidates stay linear (25.6 KB in ~76 ms).
A block whose opening line carries a solitary `$` and that must interrupt a
paragraph is unchanged from the grammar this replaces: both flows decline the
interruption, so the block stays in the paragraph. The Agent Note records that
fourth shape with its workaround, and its Testing section now states each
guard's condition instead of the revision that produced it.
Round two of review found the previous revision's decline rule too broad and
its interruption guard too eager:
- A solitary `$` inside a formula is content, not a failed closing fence, so
`$$P = \begin{cases} 1 & \text{if $x>0$} \end{cases}$$` and
`$$\text{a $x$ b}\tag{1}$$` stay display blocks. Only a full `$$` sequence
that the line does not end after makes the flow decline the candidate.
- The dollar flow's interruption check now declines instead of claiming the
interruption. Claiming it split `**before` / `$$a\$b` / `after**` into two
paragraphs and exposed its `**` markers, because the candidate it claimed
for then failed. Declining leaves the decision to upstream's own check,
which short-circuits without consuming and claims only accepted fences.
- The guard stays scoped to the dollar flow: an unconditional decline dropped
the multi-line `\[` blocks (`Prose line` followed by `\[`) that upstream has
no counterpart for.
Guards cover the solitary dollar, the tagged formula, the escaped-dollar
paragraph, and the multi-line backslash block; the first three fail against
the previous revision.
Review of the multi-line change found three behaviors it had altered:
- `$$x$$ trailing\n\n$$y$$` scanned on from the failed same-line close and
swallowed the second block's fence, rendering one broken math node where
inline math, the prose, and the display block belong. A `$$` the flow
cannot close now ends the attempt, as the single-line case already did.
- The paragraph-interruption guard sat in the shared tokenizer body, so an
unclosed `\[` candidate (`**before\n\[literal]\nafter**`) split its
paragraph and exposed the `**` markers. The guard applies to the dollar
flow only, which is the one with a competing upstream construct.
- Repeated unclosed candidates (`$$a$b` per line) scanned to EOF from every
line, making 9.6 KB of them take about four seconds in a synchronous
parse. Declining the candidate on its opening line restores linear work
(about 18 ms).
Each behavior gains a guard test that fails against the previous revision.
A `$$math` block whose opening line carries math and whose closing `$$` sits
at the end of the last math line parsed as an unclosed flow:
micromark-extension-math reads the opening line's text as fence meta and
accepts a closing fence only on a line whose content is exactly `$$`. The
flow then consumed the following document, and KaTeX rendered the block plus
that swallowed text as one error span. Fence meta was also silently dropped
because the renderer reads only the math node's value.
The compatibility layer's dollar flow now owns every `$$` fence, spans
multiple lines, and stops its paragraph-interruption check before the line
ending, as the upstream flow does; registering it after `math()` is what
gives it that precedence in micromark.