Commit Graph
20 Commits
Author SHA1 Message Date
yudshj 1d9c0ab757 revert(markdown): remove PR #4484 display-dollar parser
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.
2026-10-30 14:16:26 +08:00
Chinesezjc a5a78b88ab docs(web): state the verb tail limitation and pin its comment case 2026-09-18 15:38:24 +08:00
Chinesezjc 9930a1da95 fix(web): keep a comment out of the verb delimiter branch 2026-09-18 15:23:16 +08:00
Chinesezjc c9c836ade1 fix(web): track the failed fence second marker and align the note 2026-09-18 15:07:24 +08:00
Chinesezjc d53bbe98fe fix(web): scope the verb delimiter tail to its line and unescaped backslash 2026-09-18 15:04:57 +08:00
Chinesezjc eeaac47630 fix(web): keep a lone dollar on a later line inside the block 2026-09-18 14:49:32 +08:00
Chinesezjc 6a2692c06b fix(web): type the consumed-tail helper for the parser code unit 2026-09-18 14:45:56 +08:00
Chinesezjc 33a6a06e17 fix(web): read the fence after verb as its delimiter
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.
2026-09-18 14:44:52 +08:00
Chinesezjc 072e3465f1 refactor(web): drop the hand-rolled verbatim scan from the dollar flow
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.
2026-09-18 14:24:01 +08:00
Chinesezjc 2a4e1bcbfb fix(web): let a whitespace-only percent comment keep its fence
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.
2026-09-18 14:06:04 +08:00
Chinesezjc 5804a9e863 fix(web): keep a second percent and a starred delimiter honest
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.
2026-09-18 14:04:43 +08:00
Chinesezjc 3e0a5c3af5 fix(web): read a percent followed straight by the fence as content
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.
2026-09-18 13:48:29 +08:00
Chinesezjc d9b2e06b46 fix(web): scope the comment exception to a later line
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.
2026-09-18 13:30:28 +08:00
Chinesezjc 14a59d871e fix(web): keep a verbatim percent out of the comment state
`\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.
2026-09-18 13:29:03 +08:00
Chinesezjc 13ee2f421f fix(web): keep a TeX comment from closing a dollar block
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.
2026-09-18 13:13:15 +08:00
Chinesezjc 0913c023bb fix(web): end the dollar escape run at a line ending
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.
2026-09-18 12:43:27 +08:00
Chinesezjc 760ad03842 fix(web): keep solitary dollars and interrupting paragraphs intact
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.
2026-09-18 11:55:37 +08:00
Chinesezjc 14ead62052 fix(web): decline a dollar block whose closing fence carries text
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.
2026-09-17 23:31:34 +08:00
Chinesezjc f723892c98 fix(web): render multi-line display-dollar math
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.
2026-09-17 22:49:01 +08:00
07akioni 8d6824a84b feat: markdown 增量解析 2026-08-06 13:56:43 +08:00