Skip to content

Conversation

@OlgaRedozubova
Copy link
Contributor

@OlgaRedozubova OlgaRedozubova commented Dec 11, 2025

branch: dev/olga/markdown-it-async-patch

What's been changed:

  • Added src/markdown/async-patch.ts to monkey-patch markdown-it with asynchronous APIs:
    • Introduces core.processAsync, block.parseAsync, and inline.parseAsync with time-slicing via sliceMs and setImmediate.
    • Allows long-running Markdown parsing to run cooperatively without blocking the Node.js event loop.
  • Added src/markdown/md-inline-rule/core-inline-async.ts:
    • Implements coreInlineAsync, an async replacement for the custom coreInline rule used in mathpix-markdown-it.
    • All inline parsing paths (regular inline tokens, tabular cells, and LaTeX footnote tokens) now use await state.md.inline.parseAsync(...).
    • Preserves existing behavior for footnotes, labels, currentTag/envToInline, math attributes, and text size calculation while making execution non-blocking.
  • Introduced markdownToHTMLAsync (async pipeline entrypoint):
    • Async counterpart to markdownToHTML, using the patched markdown-it instance and async core/inline processing.
    • Designed to handle very large Markdown documents without causing long event-loop stalls, while keeping the HTML output compatible with the existing pipeline.

TODO:

  • Add test for markdownToHTMLAsync and markdownToHtmlPipelineSegmentsAsync

@OlgaRedozubova OlgaRedozubova self-assigned this Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants