Skip to content

Math: Add inline {math} role#3599

Merged
reakaleek merged 4 commits into
mainfrom
vigorous-ziconium
Jul 1, 2026
Merged

Math: Add inline {math} role#3599
reakaleek merged 4 commits into
mainfrom
vigorous-ziconium

Conversation

@reakaleek

Copy link
Copy Markdown
Member

Why

MyST defines both a block math directive 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 shared MathMarkup helper used by both the block directive and the new role, so there's one source of truth for the math markup. Docs for docs/syntax/math.md now cover both forms.

Test plan

  • dotnet test tests/Elastic.Markdown.Tests — new MathRoleTests pass, existing MathBlockTests regression-pass unchanged
  • Full Inline test suite (305 tests) passes with no regressions
  • dotnet build succeeds with 0 warnings/errors

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>
@reakaleek reakaleek requested a review from a team as a code owner July 1, 2026 08:27
@reakaleek reakaleek requested a review from a team as a code owner July 1, 2026 08:27
@reakaleek reakaleek requested a review from cotti July 1, 2026 08:27
@reakaleek reakaleek temporarily deployed to integration-tests July 1, 2026 08:27 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@reakaleek, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 234012b1-e99c-4665-b809-abd0e82d9e73

📥 Commits

Reviewing files that changed from the base of the PR and between 1020b1d and 009d7bc.

📒 Files selected for processing (3)
  • Directory.Packages.props
  • src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs
  • src/Elastic.Markdown/Myst/Roles/Math/MathRoleRenderer.cs
📝 Walkthrough

Walkthrough

Introduces support for a {math} inline role rendered client-side via KaTeX, alongside the existing math block directive. A new internal MathMarkup.WriteHtml helper centralizes math HTML generation (div for display, span for inline), used by both the refactored directive renderer and a new MathRoleHtmlRenderer. Adds MathRole, MathParser, and a Markdig InlineMathExtension registered via UseInlineMath() in the pipeline. Fixes an ambiguous Math.Max call. Adds tests and documentation for the new inline role.

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>"
Loading

Related PRs: None found.

Suggested labels: enhancement, documentation

Suggested reviewers: None identified.

🐇 A whisper of math, both block and inline,
KaTeX renders it, ever so fine,
A span for the short, a div for the tall,
One helper class now serves them all,
Hop along, carrot, the equations align.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding an inline {math} role.
Description check ✅ Passed The description matches the changeset and accurately explains the inline math role, shared rendering, docs, and tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch vigorous-ziconium

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs (1)

698-702: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Name the boolean argument at the call site.

block.IsDisplayMath is passed positionally into isDisplay. 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 value

Consider a more neutral home for the shared helper.

MathMarkup is placed under Myst/Directives/Math/ but is (per the PR) also consumed by the Myst/Roles/Math/ inline role, creating a Roles → Directives namespace dependency for a helper that belongs to neither feature specifically. A shared Myst/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

📥 Commits

Reviewing files that changed from the base of the PR and between 5059e85 and 1020b1d.

📒 Files selected for processing (9)
  • docs/syntax/math.md
  • src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs
  • src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs
  • src/Elastic.Markdown/Myst/MarkdownParser.cs
  • src/Elastic.Markdown/Myst/Roles/Math/MathParser.cs
  • src/Elastic.Markdown/Myst/Roles/Math/MathRole.cs
  • src/Elastic.Markdown/Myst/Roles/Math/MathRoleRenderer.cs
  • src/Elastic.Markdown/Myst/Roles/RoleParser.cs
  • tests/Elastic.Markdown.Tests/Inline/MathRoleTests.cs

Comment thread src/Elastic.Markdown/Myst/Directives/Math/MathMarkup.cs Outdated
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>
@reakaleek reakaleek temporarily deployed to integration-tests July 1, 2026 08:37 — with GitHub Actions Inactive
@reakaleek reakaleek temporarily deployed to integration-tests July 1, 2026 08:43 — with GitHub Actions Inactive
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>
@reakaleek reakaleek temporarily deployed to integration-tests July 1, 2026 08:51 — with GitHub Actions Inactive
@reakaleek reakaleek merged commit 2930de5 into main Jul 1, 2026
33 of 34 checks passed
@reakaleek reakaleek deleted the vigorous-ziconium branch July 1, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants