Skip to content

fix: keep paragraphs joined across indented line comments - #17

Merged
sou1118 merged 2 commits into
mainfrom
fix/indented-comment-parbreak
Aug 20, 2026
Merged

fix: keep paragraphs joined across indented line comments#17
sou1118 merged 2 commits into
mainfrom
fix/indented-comment-parbreak

Conversation

@sou1118

@sou1118 sou1118 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #9, closes #16.

An indented line comment between two sentences still split the paragraph in the diff output: the reconstructed source kept a whitespace-only line (the comment's indent), and Typst treats such lines as paragraph breaks.

Fix

Generalize the Space-node guard from #9. The old guard only skipped a Space whose text was exactly "\n" when the buffer ended with '\n'. Now, when a Space starts with a newline and the buffer already ends in a newline plus optional spaces/tabs (the dropped comment's indent), the indent is truncated and the duplicate newline skipped, so no blank or whitespace-only line can appear.

The invariant from #9 still holds: bare blank lines are always a single Parbreak token, so two Space nodes spanning a newline can only arise from a dropped comment between them — intentional paragraph breaks are unaffected.

Tests

  • Unit tests: plain comment (regression for fix: preserve paragraph structure when line comments separate inline text #9, which shipped without tests), indented comment, consecutive indented comments, and a blank-line-plus-comment case that must keep its paragraph break.
  • Integration test: the issue's reproduction, asserting the output contains no whitespace-only line.
  • All 65 tests pass; cargo fmt --check and clippy -D warnings are clean.

Summary by CodeRabbit

  • Bug Fixes
    • Improved paragraph and diff rendering when comments appear between lines.
    • Recognized all supported newline formats, including Windows-style line endings.
    • Removed unwanted indentation, duplicate newlines, and whitespace-only lines.
    • Preserved genuine paragraph breaks around blank lines.
    • Kept surrounding changed text contiguous when indented comments are present.

Generalize the Space-node guard from #9: when the next Space starts
with a newline and the paragraph buffer already ends in a newline plus
optional indent, drop the trailing indent and the duplicate newline.
This prevents whitespace-only lines in the output, which Typst treats
as paragraph breaks.

Closes #16
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 71713708-614a-437f-b7dd-1be14270e4ec

📥 Commits

Reviewing files that changed from the base of the PR and between 46669a0 and 4a00464.

📒 Files selected for processing (1)
  • src/parse.rs

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


📝 Walkthrough

Walkthrough

The parser now joins lines around indented comments for all supported Typst newline forms. It preserves indentation trimming and avoids false paragraph breaks. Parser and integration tests cover the behavior.

Changes

Paragraph reconstruction

Layer / File(s) Summary
Reconstruct and validate paragraphs around comments
src/parse.rs, tests/integration.rs
The parser detects and strips each supported Typst newline sequence, including CRLF. It joins comment-separated lines while preserving indentation behavior. Tests cover supported newline representations and diff rendering.

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

Merge Risk: ⚪ Minimal · up to 4a004

This localized parser fix preserves paragraph breaks while preventing indented comments from creating unintended breaks, with passing tests and checks; no actionable merge-blocking risk remains.

Possibly related issues

  • Issue 16 — Fixes the indented line-comment paragraph break described by the issue.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
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 fix: keeping paragraphs joined across indented line comments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/indented-comment-parbreak

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.

@sou1118

sou1118 commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Actionable comments posted: 1

🤖 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/parse.rs`:
- Around line 79-91: Update the newline handling in the joined logic of the
paragraph parser to recognize every Typst newline form using
typst_syntax::is_newline, including treating CRLF as a single sequence before
removing the prefix. Preserve the existing paragraph joining behavior while
preventing retained indentation and duplicate newlines, and add regression
coverage for each supported newline form.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f03f05bb-7ef1-48a1-8efa-3230f286ae7f

📥 Commits

Reviewing files that changed from the base of the PR and between 51165f3 and 46669a0.

📒 Files selected for processing (2)
  • src/parse.rs
  • tests/integration.rs

Comment thread src/parse.rs Outdated
@sou1118
sou1118 merged commit e575d9f into main Aug 20, 2026
9 checks passed
@sou1118
sou1118 deleted the fix/indented-comment-parbreak branch August 20, 2026 15:56
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.

Indented line comments still introduce a paragraph break in diff output

1 participant