Skip to content

Start a new paragraph when an HTML block tag opens in paste - #1489

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3549-html-paste-glues-text-that-comes
Oct 30, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3549-html-paste-glues-text-that-comes

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd/richclip.rs:121-170 (html_to_body, opening-tag handling; is_block at :190) (no existing issue): HTML paste glues text that comes before a block tag to the text inside it.

Cause

html_to_body only called new_para when a block tag closed (</div>, </p>, </li>, </h1> and so on). Opening tags never started a paragraph, so text before a block tag was glued to the text inside it (Hello<div>world</div> became Helloworld).

Fix

In the opening-tag path, html_to_body now calls new_para when is_block(&name) is true. new_para does nothing when the current paragraph is empty, so adjacent or nested block tags don't produce empty paragraphs. The regression test covers div, p, li and h1.

Verified

  • Regression test cmd::richclip::tests::text_before_opening_block_tag_is_separate_paragraph: fails on main without the fix and passes with it (cargo test -p deckcraft-engine --lib text_before_opening_block_tag_is_separate_paragraph).
  • cargo xtask ci passes except backstage::tests::start_screen_opens_the_palette_and_preferences, which also fails on main without this change.

Not changed

The closing-tag handling, the br/hr handling and the tag lists (is_block, tag_kind) are unchanged.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Improved paragraph spacing when converting HTML content to text. Text before block elements such as divisions, paragraphs, list items, and headings is now kept separate from the content that follows, making the resulting text easier to read.

Found while testing crates/engine/src/cmd/richclip.rs:121-170 (html_to_body, opening-tag handling; is_block at :190)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6d09d37 and fd102fb.

Files selected for processing: 1
  • crates/engine/src/cmd/richclip.rs

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

Walkthrough

Opening block tags in html_to_body now start a new paragraph, matching the existing handling of closing block tags. A test checks this behavior for div, p, li, and h1.

Changes: Rich clipboard paragraph spacing

Layer / File(s) Summary
Opening block tag paragraph boundaries
crates/engine/src/cmd/richclip.rs
Opening block tags now start a new paragraph. A test checks that text before opening div, p, li, and h1 tags is separate from the block contents.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: dylanmtaylor

Merge Risk: Minimal · up to fd102

The change implements the intended paragraph separation, with no established merge-blocking risk.

Architecture risk: Medium · up to fd102

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/engine/src/cmd/richclip.rs: Opening block tags now start a new paragraph; previously only closing block tags did so.
  • observed — Modified behavior in crates/engine/src/cmd/richclip.rs: Added a test asserting that text before an opening div, p, li, or h1 is in a separate paragraph from the tag’s contents.

Reliability and maintainability

  • inferred — Risk-relevant change factors for crates: blast_radius_2; direct_dependents_2
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 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 change: starting a new paragraph when an HTML block tag opens during paste handling.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Harrison-Booth

Copy link
Copy Markdown
Contributor

On Linux, I ran CARGO_BUILD_JOBS=2 cargo test -p deckcraft-engine --lib text_before_opening_block_tag_is_separate_paragraph (passed), then a temporary edit.paste test covering adjacent <p> tags, an empty middle paragraph, and nested <div> tags (passed: 2, 3, and 3 paragraphs; the empty paragraph was preserved). git merge-tree against origin/main was clean. I did not run cargo xtask ci, the full suite, GUI checks, or Windows/macOS builds.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 8713686 into storytold:main Oct 30, 2026
7 checks passed
@echelon

echelon commented Oct 30, 2026

Copy link
Copy Markdown
Member

Landed on main, thank you @Silvertree2010 for the contribution! If you haven't already, come join us on Discord: https://discord.gg/artcraft

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.

4 participants