Skip to content

fix: keep a label on its added equation - #47

Open
benmandrew wants to merge 1 commit into
sou1118:mainfrom
benmandrew:fix/label-after-wrapped-block
Open

benmandrew wants to merge 1 commit into
sou1118:mainfrom
benmandrew:fix/label-after-wrapped-block

Conversation

@benmandrew

@benmandrew benmandrew commented Oct 20, 2026 •

Copy link
Copy Markdown

A label after a changed display equation is parsed as its own block. The output puts it after the #diff-added[...] wrapper, so the label attaches to the wrapper instead of the equation. Any reference to it then fails with "cannot reference styled". To reproduce, diff these two versions:

#set math.equation(numbering: "(1)")
$ x = 1 $ <eq-main>   // new version: $ x = 2 $ <eq-main>
See @eq-main.

The render loop now looks at the next result. When a bare label follows an added equation, the label goes inside the wrapper, next to the equation: #diff-added[$ x = 2 $ <eq-main>]. A small next_label helper finds the labels that would otherwise be output bare.

Summary by CodeRabbit

  • Bug Fixes
    • Equation changes now keep their associated label within the same added-content highlight.
    • Prevents the label from appearing as a separate standalone line.

A label after a display equation is parsed as its own block and rendered
after the equation's #diff-added wrapper, so it labels the wrapper. Any
reference to it then fails with "cannot reference styled". Render the
label inside the wrapper, next to the equation.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 23:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

The renderer now checks whether an added equation is followed by a label-only paragraph. When eligible, it includes the label in the equation’s added diff wrapper. An integration test covers a changed equation that retains its label.

Changes: Equation label rendering

Layer / File(s) Summary
Keep labels with added equations
src/render.rs, tests/integration.rs
A helper identifies label-only unchanged or added paragraphs. When one follows an added equation, the renderer consumes it and includes its trimmed text in the added diff wrapper. The integration test checks that the label is not emitted as a separate line.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: sou1118

Merge Risk: ⚪ Minimal · up to ab9c3

The changed equation and its following label render together. No actionable merge-blocking risk is established.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving a label with its added equation.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files.
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
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Choose a reason for hiding this comment

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

🔇 Additional comments: 3
src/render.rs: 2

21-43: LGTM!


115-126: LGTM!

tests/integration.rs: 1

221-222: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Use an exact assertion for the rendered equation.

contains checks pass if unrelated output changes elsewhere. The test only checks one fragment of the body. Extract the body after the preamble and compare it with assert_eq!. The comparison then catches unexpected extra or reordered output.

As the retrieved learning says, prefer exact assertions such as assert_eq! over loose containment checks.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59622cad-dc84-4c19-b97c-b550cb490420
📥 Commits

Reviewing files that changed from the base of the PR and between a4761cc and ab9c360.

📒 Files selected for processing: 2
  • src/render.rs
  • tests/integration.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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.

2 participants