Normalize math rendering in docs panel and LSP tooltips#8315
Normalize math rendering in docs panel and LSP tooltips#8315mscolnick merged 3 commits intomarimo-team:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
dmadisetti
left a comment
There was a problem hiding this comment.
Thanks for the PR. It looks great, but does feel like a lot of code. I think breaking out into marimo/_utils/normalize_math.py might be better for the backed.
It's also not immediately obvious how the extraction works. Top level comments on the regex and maybe some doc strings on the more complex functions could go a long way!
marimo/_runtime/complete.py
Outdated
| # We also add '/' for file path completion. | ||
| COMPLETION_TRIGGER_CHARACTERS = frozenset({".", "(", ",", "/"}) | ||
|
|
||
| _MATH_ROLE_PATTERN = re.compile(r"(?<!`):math:`([^`\n]+)`") |
There was a problem hiding this comment.
This is a lot of code. I wonder if it could go somewhere else? Can you give examples of the patterns you are trying to match as well?
|
Sorry for the late reply, should I abort this in lieu of #8348 ? |
a04b960 to
5a7326d
Compare
for more information, see https://pre-commit.ci
|
@dmadisetti even with #8348 I was getting issues with the math rendering in optax documentation. I have extended display_math.py to handle more formats that were failing before. I have also added normalize-markdown-math.ts so that this math is also rendered in tooltips/ other docs. Examples corresponding to each regex pattern have also been added. |
There was a problem hiding this comment.
Pull request overview
This PR normalizes math rendering in documentation displayed in both the docs explorer and LSP tooltips by extending the backend markdown preprocessing and adding frontend LSP normalization utilities to handle multiple math syntax variants commonly used in Python docstrings.
Changes:
- Extended backend
DisplayMathPreprocessorto normalize RST math directives (:math:,.. math::), LaTeX delimiters (\(...\),\[...\]), and HTML code-tag variants while preserving fenced code blocks and inline code literals - Added frontend
normalize-markdown-math.tsutility with similar normalization logic applied to LSP documentation responses (hover, completion, signature help) - Modified docstring conversion flow in
complete.pyto prefer markdown rendering when math syntax is detected, ensuring consistent TeX pipeline usage
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| marimo/_output/md_extensions/display_math.py | Extended DisplayMathPreprocessor with methods to normalize RST math directives, LaTeX delimiters, and handle inline code/fenced blocks; fixes escape sequence in test expectations |
| marimo/_runtime/complete.py | Added math syntax detection, error handling for docstring_to_markdown.UnknownFormatError, and math-aware fallback path in docstring conversion |
| tests/_output/test_md.py | Added tests for RST math directive normalization, math role/delimiter conversion, fenced code preservation; fixed escape sequences in LaTeX macro tests |
| tests/_runtime/test_complete.py | Added comprehensive tests for math directive normalization in docstrings, including edge cases like unindented blocks, fenced code, and class init handling |
| frontend/src/core/codemirror/lsp/normalize-markdown-math.ts | New utility implementing math syntax normalization for LSP documentation with fenced/inline code preservation |
| frontend/src/core/codemirror/lsp/notebook-lsp.ts | Integrated math normalization into hover, completion, completionItemResolve, and signatureHelp responses |
| frontend/src/core/codemirror/lsp/tests/normalize-markdown-math.test.ts | Tests for frontend math normalization covering RST directives, LaTeX delimiters, code block preservation |
| frontend/src/core/codemirror/lsp/tests/notebook-lsp.test.ts | Integration tests verifying math normalization across all LSP response types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📝 Summary
This PR fixes math rendering consistency for documentation shown in both the docs explorer and LSP tooltips by normalizing additional math syntaxes in the backend markdown path and frontend LSP docs path.
🔍 Description of Changes
...while preserving existing$$...$$ spacing behavior.
Kept backend docstring conversion path thin in completion flow so math docs reliably go through markdown rendering.
Added frontend LSP normalization utility and applied it to:
Preserved fenced code and inline code literals (no unwanted math conversion inside code examples).
Added concise comments for regex patterns to clarify exactly what each pattern matches.
Tests
Screenshot
📋 Checklist