mathpix-markdown-it
Version:
Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)
137 lines (99 loc) • 7.38 kB
Markdown
# March 2026
## [2.0.38] - Fix infinite loop in `inlineMmdIcon` and `inlineDiagbox` silent mode
- Bug Fix:
- Fixed page freeze when `\icon{...}` or `\diagbox{...}` appeared inside link labels (e.g. `[\icon{unknown}]`). The inline rules returned `true` in silent mode without advancing `state.pos`, causing an infinite loop in markdown-it's `parseLinkLabel` → `skipToken`.
- Refactoring:
- `inlineMmdIcon` and `inlineDiagbox` refactored to follow the `if (!silent) { ... } state.pos = endPos; return true;` pattern used by all other inline rules.
- `mmd-icon.ts`: extracted `endPos` constant, eliminated 6 duplicated position assignments.
- `diagbox-inline.ts`: moved `extractNextBraceContent` before the silent check so `endIndex` is available in both modes.
- Tests:
- Added 4 test cases for icon and diagbox inside link labels and bare brackets.
- Docs:
- Added implementation details in `pr-specs/2026-03-fix-silent-mode-state-pos.md`.
## [2.0.37] - CSS scoping and style module cleanup
- CSS Scoping:
- All MMD class selectors now have `#preview-content`/`#setText` scoped variants for specificity boost.
- Bare selectors preserved as fallback for `markdownToHTML()` (no wrapper).
- Style Architecture:
- New `buildStyles(opts: StyleBundleOpts)` single CSS builder — all assembly methods delegate here.
- `MathpixStyle` restructured into 10 composable sub-functions.
- Color constants extracted into `src/styles/colors.ts`.
- `halpers.ts` renamed to `helpers.ts`.
- Improvements:
- `.tabular` now renders consistently regardless of context (standalone vs nested inside a list). Previously, list context could affect table width and font size via cascade. Fixed with explicit `margin: 0 0 1em`, `font-size: inherit`, and other defensive defaults.
- `useColors=false` now correctly omits blockquote border, table border, and mark background colors.
- `getMathpixStyle(useColors=false)` now also omits `ContainerStyle` colors (body text, headings, links, captions). Previously `ContainerStyle()` was always called with default colors.
- Bug Fixes:
- `div.svg-container` child combinator consistency (`>` for both `#preview-content` and `#setText`).
- `loadMathJax` updates existing `#Mathpix-styles` element instead of skipping.
- Breaking Changes:
- `scaleEquation` parameter removed from `loadMathJax`, `getMathpixStyleOnly`, `getMathpixStyle`, and `getMathpixMarkdownStyles`. It was never used in CSS output. If you were passing it positionally, shift your arguments. Use `buildStyles(opts)` for a named-parameter alternative.
- Dead Code Removed:
- `.empty` selector (never generated), `.preview-right` selector (used as id, not class).
- Docs:
- Added implementation details in `pr-specs/2026-03-mmd-css-scoping.md`.
# February 2026
## [2.0.36] - 16 February 2026
- Math Output Format:
- Added `output_format` option to `TOutputMath` to control which math format is placed in HTML output.
- `'svg'` (default): Pre-rendered SVG with hidden formats, works offline.
- `'mathml'`: Native `<math>` elements only, smaller file size, requires client-side rendering.
- `'latex'`: Raw LaTeX with original delimiters, smaller file size, requires client-side rendering.
- Browser Rendering Script (`auto-render.js`):
- New browser bundle for client-side math rendering at `es5/browser/auto-render.js`.
- Renders MathML or LaTeX content to SVG.
- Generates hidden format elements for context menu compatibility.
- Configurable accessibility support via `MathpixAccessibilityConfig`:
- `assistive_mml`: Add `<mjx-assistive-mml>` for screen readers.
- `include_speech`: Add `aria-label` with speech text.
- Browser Speech Script (`add-speech.js`):
- New browser bundle for adding speech to already-rendered SVG at `es5/browser/add-speech.js`.
- Use when SVG was rendered with `assistiveMml: true` but without `sre` (speech).
- Loads SRE dynamically and adds `aria-label`, `role="math"`, `tabindex` to `mjx-container` elements.
- Requires `mjx-assistive-mml` to be present in the rendered output.
- Exposes `window.MathpixSpeech.addSpeechToRenderedMath(container?)`.
- Accessibility:
- `mjx-assistive-mml` is no longer marked with `aria-hidden="true"` when accessibility options are enabled. Previously, the assistive MathML element was hidden from screen readers even when the user explicitly requested accessibility via `assistiveMml: true` or `sre`. Now, if any accessibility option is set, the MathML content is exposed to assistive technology — either via `aria-labelledby` (pointing to the assistive MML) or via `aria-label` (SRE speech text). This affects both server-side rendering (`addAriaToMathHTML`) and the new browser bundles.
- Fixes:
- Fixed centering issue for equations with numbering inside `.math-block[data-width="full"]`.
- Docs:
- Added implementation details in `pr-specs/2026-01-html-math-output-options.md`.
## [2.0.35] - 13 February 2026
- Tabular:
- When `forMD` option is set, `renderTableCellContent` now delegates `image`/`includegraphics` rendering to the caller's render rules instead of hardcoding ``.
- Added `isTableCell` meta flag on child tokens when `forMD` is set, allowing render rules to escape pipe characters in alt text.
- Added null-safety for `attrGet('alt')` in the default image rendering path.
- Docs:
- Added implementation details in `pr-specs/2026-02-formd-delegate-image-rendering-in-table-cells.md`.
## [2.0.34] - 7 February 2026
- Table/Figure:
- Fixed renderer hang when a `\begin{table}` or `\begin{figure}` has a malformed closing tag (e.g. `\end{table>`).
- `BeginTable` no longer consumes content across multiple table/figure environments when the first is unclosed.
- Lists (inline):
- Fixed `latexListEnvInline` silent mode to advance `state.pos`, preventing infinite loops in `skipToken` when `\begin{itemize}` or `\begin{enumerate}` appears in inline content.
- Docs:
- Added implementation details in `pr-specs/2026-02-fix-stuck-render-malformed-table-close.md`.
# January 2026
## [2.0.33] - 27 January 2026
- Tabular:
- Fixed rendering of tabular environments following nested tabular placeholders that expand to lists.
- Block parsing status is now propagated from nested sub-tabulars to parent cells to preserve line breaks.
- Centralized block detection logic into `detectLocalBlock()`.
- Docs:
- Added implementation details in `pr-specs/2026-01-nested-tabular-text-prefix-with-lists.md`.
## [2.0.32] - 21 January 2026
- Tabular:
- Added support for LaTeX `itemize` and `enumerate` lists inside table cells.
- Nested lists now render with correct markers per level.
- Custom (`\item[X]`) and empty (`\item[]`) markers are preserved.
- Fixed edge cases with lists mixed with nested tabular, math, and inline formatting.
- Exports:
- Markdown: list items are separated with `<br>` inside table cells.
- TSV/CSV: list items are separated by newline characters.
- Improved export fidelity for tables containing nested lists.
- Parsing:
- Tabular cells conditionally switch to block parsing when list environments are detected.
- Prevent nested `.table_tabular` elements from being processed as top-level tables.
- Docs:
- Detailed implementation notes and test coverage are documented in
`pr-specs/2026-01-itemize-support-inside-tabular.md`.