Math: Add inline {math} role#3599
Conversation
MyST defines both a block math directive and an inline math role, but
only the block directive existed here. Add the {math} role for LaTeX
expressions inside a sentence, sharing the HTML rendering logic with
the block directive via a new MathMarkup helper.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughIntroduces support for a Sequence Diagram(s)sequenceDiagram
participant Markdown as Markdown Source
participant MathParser
participant MathRole
participant MathRoleHtmlRenderer
participant MathMarkup
Markdown->>MathParser: "{math}`E = mc^2`"
MathParser->>MathRole: CreateRole(role, content)
MathRole->>MathRoleHtmlRenderer: Write(renderer, MathRole)
MathRoleHtmlRenderer->>MathMarkup: WriteHtml(content, isDisplay=false)
MathMarkup-->>Markdown: "<span class=\"math\">E = mc^2</span>"
Related PRs: None found. Suggested labels: enhancement, documentation Suggested reviewers: None identified. 🐇 A whisper of math, both block and inline, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs (1)
698-702: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winName the boolean argument at the call site.
block.IsDisplayMathis passed positionally intoisDisplay. As per coding guidelines,**/*.cs: "Boolean parameters must be named at call sites."♻️ Proposed fix
- MathMarkup.WriteHtml(renderer, block.Content, block.IsDisplayMath, block.Label); + MathMarkup.WriteHtml(renderer, block.Content, isDisplay: block.IsDisplayMath, block.Label);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs` around lines 698 - 702, The boolean argument passed from WriteMathBlock to MathMarkup.WriteHtml is positional and should be named at the call site. Update the call in WriteMathBlock so block.IsDisplayMath is passed using the isDisplay named argument, keeping the rest of the arguments unchanged.Source: Coding guidelines
src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs (1)
13-23: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a more neutral home for the shared helper.
MathMarkupis placed underMyst/Directives/Math/but is (per the PR) also consumed by theMyst/Roles/Math/inline role, creating a Roles → Directives namespace dependency for a helper that belongs to neither feature specifically. A sharedMyst/Math/MathMarkup.cs(or similar neutral location) would avoid coupling one vertical slice to another.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs` around lines 13 - 23, Move the shared MathMarkup helper out of the Myst/Directives/Math area into a neutral shared location so it can be used by both the directive and the inline role without creating a Roles-to-Directives dependency. Update the MathMarkup class placement and any references from the Myst/Roles/Math code path to point to the new shared location, keeping the WriteHtml API unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs`:
- Around line 15-22: The label value in MathMarkup.WriteHtml is interpolated
directly into the id attribute without escaping, which can allow malformed
markup; update WriteHtml to encode or otherwise HTML-escape the label before
building labelAttr. Use the existing MathMarkup.WriteHtml flow and keep the fix
localized to the label/id generation so the rendered math tag still writes
content and tags as before.
---
Nitpick comments:
In `@src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs`:
- Around line 698-702: The boolean argument passed from WriteMathBlock to
MathMarkup.WriteHtml is positional and should be named at the call site. Update
the call in WriteMathBlock so block.IsDisplayMath is passed using the isDisplay
named argument, keeping the rest of the arguments unchanged.
In `@src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs`:
- Around line 13-23: Move the shared MathMarkup helper out of the
Myst/Directives/Math area into a neutral shared location so it can be used by
both the directive and the inline role without creating a Roles-to-Directives
dependency. Update the MathMarkup class placement and any references from the
Myst/Roles/Math code path to point to the new shared location, keeping the
WriteHtml API unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 091cf8df-4e8b-455b-a272-d6fb59d6d95c
📒 Files selected for processing (9)
docs/syntax/math.mdsrc/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cssrc/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cssrc/Elastic.Markdown/Myst/MarkdownParser.cssrc/Elastic.Markdown/Myst/Roles/Math/MathParser.cssrc/Elastic.Markdown/Myst/Roles/Math/MathRole.cssrc/Elastic.Markdown/Myst/Roles/Math/MathRoleRenderer.cssrc/Elastic.Markdown/Myst/Roles/RoleParser.cstests/Elastic.Markdown.Tests/Inline/MathRoleTests.cs
GHSA-v5pm-xwqc-g5wc flags Microsoft.OpenApi <= 3.5.3 for a high severity circular schema reference issue. CI restore fails with TreatWarningsAsErrors since the advisory now surfaces as NU1903 on every build, unrelated to this branch's changes. 3.5.4 is the first patched version. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…@coderabbitai) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Aligns MathMarkup.WriteHtml's parameter name with MathBlock.IsDisplayMath, the property it's populated from at the block call site. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Why
MyST defines both a block
mathdirective and an inline{math}role, but this repo only had the block directive. Authors had no way to write a short LaTeX expression inside a sentence without dropping into a standalone block.What
Adds the inline
{math}role, rendering to the same<span class="math">markup KaTeX already picks up client-side. The HTML rendering logic is extracted into a sharedMathMarkuphelper used by both the block directive and the new role, so there's one source of truth for the math markup. Docs fordocs/syntax/math.mdnow cover both forms.Test plan
dotnet test tests/Elastic.Markdown.Tests— newMathRoleTestspass, existingMathBlockTestsregression-pass unchangedInlinetest suite (305 tests) passes with no regressionsdotnet buildsucceeds with 0 warnings/errors