mathpix-markdown-it 2.0.39 → 2.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +2 -0
  2. package/doc/changelog.md +27 -0
  3. package/es5/browser/auto-render.js +1 -1
  4. package/es5/bundle.js +4 -4
  5. package/es5/index.js +1 -1
  6. package/lib/components/mathpix-markdown/index.js +2 -1
  7. package/lib/components/mathpix-markdown/index.js.map +1 -1
  8. package/lib/markdown/common/consts.d.ts +4 -0
  9. package/lib/markdown/common/consts.js +15 -5
  10. package/lib/markdown/common/consts.js.map +1 -1
  11. package/lib/markdown/index.js +2 -1
  12. package/lib/markdown/index.js.map +1 -1
  13. package/lib/markdown/mathpix-markdown-plugins.js +2 -1
  14. package/lib/markdown/mathpix-markdown-plugins.js.map +1 -1
  15. package/lib/markdown/md-block-rule/begin-tabular/common.d.ts +15 -1
  16. package/lib/markdown/md-block-rule/begin-tabular/common.js +55 -9
  17. package/lib/markdown/md-block-rule/begin-tabular/common.js.map +1 -1
  18. package/lib/markdown/md-block-rule/begin-tabular/index.d.ts +3 -0
  19. package/lib/markdown/md-block-rule/begin-tabular/index.js +6 -5
  20. package/lib/markdown/md-block-rule/begin-tabular/index.js.map +1 -1
  21. package/lib/markdown/md-block-rule/begin-tabular/multi-column-row.d.ts +2 -0
  22. package/lib/markdown/md-block-rule/begin-tabular/multi-column-row.js +6 -3
  23. package/lib/markdown/md-block-rule/begin-tabular/multi-column-row.js.map +1 -1
  24. package/lib/markdown/md-block-rule/begin-tabular/parse-tabular.d.ts +2 -1
  25. package/lib/markdown/md-block-rule/begin-tabular/parse-tabular.js +77 -50
  26. package/lib/markdown/md-block-rule/begin-tabular/parse-tabular.js.map +1 -1
  27. package/lib/markdown/md-block-rule/begin-tabular/sub-tabular.d.ts +3 -1
  28. package/lib/markdown/md-block-rule/begin-tabular/sub-tabular.js +19 -5
  29. package/lib/markdown/md-block-rule/begin-tabular/sub-tabular.js.map +1 -1
  30. package/lib/markdown/md-block-rule/begin-tabular/tabular-td.d.ts +3 -3
  31. package/lib/markdown/md-block-rule/begin-tabular/tabular-td.js +10 -4
  32. package/lib/markdown/md-block-rule/begin-tabular/tabular-td.js.map +1 -1
  33. package/lib/markdown/md-core-rules/set-positions.js +90 -15
  34. package/lib/markdown/md-core-rules/set-positions.js.map +1 -1
  35. package/lib/markdown/md-inline-rule/tabular.js +2 -1
  36. package/lib/markdown/md-inline-rule/tabular.js.map +1 -1
  37. package/lib/markdown/md-latex-footnotes/block-rule.js +72 -3
  38. package/lib/markdown/md-latex-footnotes/block-rule.js.map +1 -1
  39. package/lib/markdown/md-renderer-rules/render-tabular.js +3 -2
  40. package/lib/markdown/md-renderer-rules/render-tabular.js.map +1 -1
  41. package/lib/markdown/md-theorem/block-rule.js +10 -6
  42. package/lib/markdown/md-theorem/block-rule.js.map +1 -1
  43. package/lib/mathpix-markdown-model/index.d.ts +2 -0
  44. package/lib/mathpix-markdown-model/index.js +2 -1
  45. package/lib/mathpix-markdown-model/index.js.map +1 -1
  46. package/package.json +1 -1
  47. package/pr-specs/2026-05-footnote-perf-and-parser-invariants.md +246 -0
  48. package/pr-specs/2026-05-tabular-vertical-align-bracket.md +270 -0
package/README.md CHANGED
@@ -913,6 +913,7 @@ The `MathpixMarkdown` React element accepts the following props:
913
913
  | `showPageBreaks` | boolean;*`false`* | Hidden tags will be shown in html like page break |
914
914
  | `centerImages` | boolean;*`true`* | Center align images by default |
915
915
  | `centerTables` | boolean;*`true`* | Center align tables by default |
916
+ | `defaultCellVerticalAlign` | "top" \| "middle" \| "bottom";*`undefined`* | Fallback vertical alignment for tabular cells without an explicit `\begin{tabular}[t/c/b]{...}` bracket. Per-column `m`/`p`/`b` and any explicit `[t]/[c]/[b]` source bracket always override. Unset → no override. |
916
917
  | `validateLink` | function;*`null`* | The function `(url: string) => void` to override md link validator |
917
918
  | `enableCodeBlockRuleForLatexCommands` | boolean;*`false`* | By default, if latex commands are indented (4 spaces / 1 tab) they do not become `Code Blocks`. |
918
919
  | `parserErrors` | [ParserErrors](https://github.com/Mathpix/mathpix-markdown-it#parsererrors);*`{}`* | Sets options to output parser errors for equations and tabular |
@@ -947,6 +948,7 @@ The `MathpixMarkdown` React element accepts the following props:
947
948
  | `showPageBreaks` | boolean;*`false`* | Hidden tags will be shown in html like page break |
948
949
  | `centerImages` | boolean;*`true`* | Center align images by default |
949
950
  | `centerTables` | boolean;*`true`* | Center align tables by default |
951
+ | `defaultCellVerticalAlign` | "top" \| "middle" \| "bottom";*`undefined`* | Fallback vertical alignment for tabular cells without an explicit `\begin{tabular}[t/c/b]{...}` bracket. Per-column `m`/`p`/`b` and any explicit `[t]/[c]/[b]` source bracket always override. Unset → no override. |
950
952
  | `validateLink` | function;*`null`* | The function `(url: string) => void` to override md link validator |
951
953
  | `enableCodeBlockRuleForLatexCommands` | boolean;*`false`* | By default, if latex commands are indented (4 spaces / 1 tab) they do not become `Code Blocks`. |
952
954
  | `parserErrors` | [ParserErrors](https://github.com/Mathpix/mathpix-markdown-it#parsererrors);*`{}`* | Sets options to output parser errors for equations and tabular |
package/doc/changelog.md CHANGED
@@ -1,3 +1,30 @@
1
+ # May 2026
2
+
3
+ ## [2.0.40] - Tabular vertical-align bracket and footnote performance
4
+
5
+ - Tabular vertical alignment:
6
+ - Parse the optional `[t]/[c]/[b]` bracket on `\begin{tabular}` (standard LaTeX2e syntax) and use it as the row-level vertical-align default for `l/c/r/S` columns. Per-column `m`/`p`/`b` continues to override.
7
+ - Cell-level inference: when an outer cell's content includes a nested `\begin{tabular}[t/c/b]`, the outer `<td>` inherits that vertical-align (matching LaTeX baseline semantics — the cell containing the `[t]` inner tabular sits at the top of the row). Per-column `m`/`p`/`b` on the outer column still wins. Cell-level inference overrides the row-level bracket for that single cell.
8
+ - In `forLatex`, every `td_open` of a tabular with an effective bracket carries `meta.parentBracket` (`'t'`/`'c'`/`'b'`) — the bracket of THIS table, set on every cell of that table. Consumers walking forLatex tokens see parent context directly on each `<td>` without re-deriving from the parent `table_open`. `AddTd` and `AddTdSubTable` accept an optional `meta?: TTdMeta` parameter to attach this and other forLatex-specific cell info.
9
+ - New option `defaultCellVerticalAlign?: 'top' | 'middle' | 'bottom'`. HTML rendering: applies as the fallback for `\begin{tabular}` blocks without an explicit bracket. Explicit source bracket always wins. Default unset is byte-identical to legacy on existing MMD. `'middle'` propagates to regular `l/c/r/S` cells (matches existing default), but is a no-op for `\multicolumn` / `\multirow` cells (preserves legacy no-vertical-align on multicol).
10
+ - `forLatex` round-trip: for `'top'`/`'bottom'` (top-level only) the option's value is injected into `tableOpen.meta.bracket` so the consumer can serialize `\begin{tabular}[pos]{...}`. Nested absent-bracket tabulars stay bracket-less to preserve round-trip.
11
+ - `\multicolumn` / `\multirow` cells inherit `'t'`/`'b'` from any source (bracket or option), and `'c'` only from an explicit source bracket — never from option `'middle'`. Plain `\multicolumn{}` / `\multirow{}` in an absent-bracket tabular continues to emit no `vertical-align` (legacy).
12
+ - Diagbox cells always render with `vertical-align: middle` regardless of the outer tabular's bracket: `getSubTabular` flags wrappers with `hasDiagbox`, the parser skips its own vertical-align emit, and `render-tabular` adds `middle` once. Removes the duplicate `vertical-align: middle;` from existing diagbox snapshots.
13
+ - Explicit `\multirow[t/c/b]` always wins over the row-level default and emits explicit `vertical-align`. Fixes a regression where `\multirow[c]` inside `\begin{tabular}[t]{...}` silently inherited the outer `[t]` instead of honoring the user's explicit `[c]`. Two existing `\multirow[c]` snapshots in `_tabular/_data_digbox.js` updated to include the now-explicit `vertical-align: middle`.
14
+ - **Breaking change** to the exported `openTag` / `openTagG` regexes in `md-block-rule/begin-tabular`: the optional `[pos]` bracket is now a capture group. New shape is `match[1]` = bracket pos (`t`/`c`/`b` or `undefined`), `match[2]` = column spec. Previously `match[1]` = column spec. Consumers calling `openTag.exec(src)[1]` / `src.match(openTag)[1]` for the column spec must read `[2]` instead. `openTagTabular` and `BEGIN_TABULAR_INLINE_RE` (presence-check regexes) likewise allow the optional bracket but keep their existing capture groups.
15
+ - `getParams` (column-spec parser) now skips an optional `[pos]` before `{` and returns the normalized bracket position.
16
+
17
+ - Footnote rule performance:
18
+
19
+ - `latex_footnote_block` / `latex_footnotetext_block`: per-state position cache + per-line token guard turn the O(N×M) accumulation scan into one O(|src|) sweep per parse and O(1) per subsequent block-start. ~120× speedup on a 2.45 MB MMD with 706 long tabular blocks (worst case for the pre-change Phase 1 scan); HTML output byte-identical.
20
+ - `setChildrenPositions`: per-child `Object.isExtensible` guard before `.positions` assignment fixes `TypeError` thrown by frozen `SHARED_*_CLOSE` singletons inside `tabular_inline` subtrees, restoring `markdownToHTMLSegments({ addPositionsToTokens: true })` on documents with inline subtables. `link_open` branch split into strict-triple `[text](url)` (legacy snapshot-pinned math) + span fallback for fancy contents (`[**bold**](url)`, `` [`code`](url) ``, `[![alt](img)](url)`) — fixes silent NaN/off-by-N positions that existed on master.
21
+ - `BeginTheorem`: env-name validation hoisted above `state.push` in non-silent mode — unregistered environments no longer leave unmatched `<div class="theorem_block">` wrappers in the rendered HTML. Silent-mode terminator probes preserved (required by `\newtheorem` ↔ `\begin{NAME}` adjacent-line handshake).
22
+ - Behavior change for unregistered `\begin{NAME}…\end{NAME}` (e.g. TikZ): previously the rule emitted an unmatched `<div class="theorem_block">` wrapper around a math-block fallback `<span class="math-block equation-number" number="0"></span>`. Now the wrapper is gone; the inner placeholder is unchanged. `.equation-number` element count is unchanged vs master. Register via `\newtheorem{NAME}{…}` to get the body rendered.
23
+ - Behavior change for `markdownToHTMLSegments` consumers: same documents emit more segments than before because the previously unmatched wrapper was preventing segment delimiters from breaking at natural boundaries. Output bytes are unchanged; segment counts are not.
24
+ - Behavior change for highlights consumers: fancy-link span fallback (`[**bold**](url)` etc. with overlapping `highlights:`) emits empty `<span class="mmd-highlight"></span>` wrappers around markup-only inner tokens (strong_open/strong_close). Filter empty `.mmd-highlight` matches if iterating.
25
+
26
+ See `pr-specs/2026-05-footnote-perf-and-parser-invariants.md` for design and known limitations.
27
+
1
28
  # April 2026
2
29
 
3
30
  ## [2.0.39] - Optimize tabular parsing memory and performance