Skip to content

Add text wrapping to mdtablefix#32

Merged
leynos merged 4 commits intomainfrom
codex/wrap-text-paragraphs-and-list-items-at-80-columns
Jun 15, 2025
Merged

Add text wrapping to mdtablefix#32
leynos merged 4 commits intomainfrom
codex/wrap-text-paragraphs-and-list-items-at-80-columns

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 15, 2025

Summary

  • wrap paragraphs and list items at 80 columns
  • describe new behaviour in README
  • test paragraph and list item wrapping

Testing

  • cargo fmt --check
  • cargo clippy -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test
  • npx markdownlint-cli2 README.md
  • nixie **/*.md

https://chatgpt.com/codex/tasks/task_e_684e3e0cdbc08322b183dc70fb60e179

Summary by Sourcery

Add automatic text wrapping for Markdown content after table reflow, including helper functions for wrapping logic, update documentation, and add tests to ensure wrapping at 80 columns.

New Features:

  • Wrap Markdown paragraphs and list items at 80 columns

Enhancements:

  • Introduce wrap_text and flush_paragraph helpers with BULLET_RE to implement wrapping while preserving indentation and list prefixes
  • Apply text wrapping after table reflow in process_stream

Build:

  • Add textwrap crate dependency

Documentation:

  • Update README to document the new wrapping behavior

Tests:

  • Add integration tests to verify paragraph and list item wrapping at 80 columns

Summary by CodeRabbit

  • New Features
    • Added automatic wrapping of paragraphs and list items at 80 characters, improving readability while preserving Markdown formatting and indentation.
  • Documentation
    • Updated the README to mention the new text wrapping feature and clarified handling of fenced code blocks and escaped pipes.
  • Tests
    • Introduced integration tests to verify correct line wrapping for paragraphs, list items, and preservation of hard line breaks.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 15, 2025

Reviewer's Guide

Introduces an 80-column text wrapping stage for paragraphs and list items by integrating a new wrap_text helper into the processing pipeline, adding supporting regex and flush logic, accompanied by tests, documentation updates, and the textwrap dependency.

Sequence Diagram: Core Text Wrapping Interaction

sequenceDiagram
    participant P as process_stream
    participant WT as wrap_text
    participant FP as flush_paragraph
    participant TWF as textwrap::fill

    P->>WT: wrap_text(lines, 80)
    activate WT
    loop Over text segments (paragraphs/list items)
        alt Buffer needs flushing or list item processing
            WT->>FP: flush_paragraph(out_vec, current_buffer, indent, width)
            activate FP
            FP->>TWF: fill(buffered_text, effective_width)
            activate TWF
            TWF-->>FP: wrapped_text_segment
            deactivate TWF
            FP-->>WT: (appends to out_vec)
            deactivate FP
        else Regular text line
            WT->>WT: Add line to internal buffer
        end
    end
    WT-->>P: resulting_wrapped_lines
    deactivate WT
Loading

File-Level Changes

Change Details Files
Implement paragraph and list item wrapping logic
  • Add BULLET_RE to detect list prefixes
  • Create flush_paragraph helper to emit wrapped lines with indent
  • Implement wrap_text to handle code fences, tables, headings, blank lines, bullets, and paragraphs
  • Integrate wrap_text into process_stream with a fixed width of 80
src/lib.rs
Add integration tests for wrapping behavior
  • Test that long paragraphs wrap into multiple lines under 80 chars
  • Test that long list items preserve prefixes and wrap correctly
tests/integration.rs
Update README to document wrapping feature
  • Mention that paragraphs and list items are wrapped at 80 columns
  • Adjust description order to include new behavior
README.md
Add textwrap dependency
  • Include textwrap = "0.16" in Cargo.toml
Cargo.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 15, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 45 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d03cb6f and 5b5e710.

📒 Files selected for processing (3)
  • src/html.rs (6 hunks)
  • src/lib.rs (5 hunks)
  • tests/integration.rs (2 hunks)

Walkthrough

This update introduces a text wrapping feature to the Markdown processing pipeline. After tables are reflowed and HTML tables are handled, paragraphs and list items are now wrapped at 80 columns, preserving indentation and Markdown structure. The README and integration tests are updated to reflect and verify this new functionality.

Changes

File(s) Change Summary
Cargo.toml Added the textwrap crate as a new dependency.
README.md Updated description to mention paragraph and list item wrapping at 80 columns.
src/lib.rs Added text wrapping logic after table reflow, with helpers for paragraph and list handling; preserved trailing whitespace.
src/html.rs Removed .trim_end() calls to preserve trailing whitespace in HTML table processing.
tests/integration.rs Added integration tests for paragraph and list item line wrapping and preservation of hard line breaks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant process_stream
    participant wrap_text

    User->>process_stream: Provide Markdown input
    process_stream->>process_stream: Reflow Markdown tables
    process_stream->>process_stream: Convert HTML tables
    process_stream->>wrap_text: Pass processed lines
    wrap_text->>wrap_text: Wrap paragraphs and list items (80 columns)
    wrap_text-->>process_stream: Return wrapped text
    process_stream-->>User: Output final Markdown
Loading

Possibly related PRs

Poem

A rabbit hopped through lines so wide,
With textwrap's help, it turned the tide.
Paragraphs and lists, now neat and tight,
Markdown tables still shining bright.
Eighty columns, a gentle squeeze—
Markdown flows with rabbit ease!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
tests/integration.rs (1)

505-515: Test enforces an incorrect list-wrapping specification

Requiring every wrapped line to start with “- ” masks the bug above and does not match common Markdown conventions (subsequent lines should be indented, not bullet-prefixed).
Please adjust the test once the wrapping logic is fixed.

🧹 Nitpick comments (3)
Cargo.toml (1)

12-12: Pinning textwrap to an exact minor/patch version may hinder cargo update

Consider specifying a caret requirement (^0.16) or dropping the patch version so that non-breaking bug-fix releases are picked up automatically.

README.md (1)

4-5: Minor style nit

“It also wraps paragraphs and list items to 80 columns” reads a little more smoothly than “at 80 columns”.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~4-~4: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...orm width. It also wraps paragraphs and list items at 80 columns. The tool ignores f...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

src/lib.rs (1)

256-264: flush_paragraph ignores existing intra-paragraph blank lines

If the buffer contained hard line-breaks they are collapsed into spaces before wrapping, losing author intent.
Consider preserving explicit <br> or two-space line breaks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63efd3f and 98999bf.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml (1 hunks)
  • README.md (1 hunks)
  • src/lib.rs (3 hunks)
  • tests/integration.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/integration.rs (1)
src/lib.rs (1)
  • process_stream (334-392)
🪛 LanguageTool
README.md

[uncategorized] ~4-~4: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...orm width. It also wraps paragraphs and list items at 80 columns. The tool ignores f...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

🔇 Additional comments (2)
src/lib.rs (2)

249-251: Regex captures bullet prefix correctly – good
No issues here.


266-331: Edge cases: headings & fenced code blocks with indentation

FENCE_RE is anchored (^) so indented code fences (“ ```”) are not detected and may be re-wrapped.
Similarly, indented ‘#’ headings are treated as paragraph text.
Add ^\s* to both patterns or trim-start before matching.

Comment thread src/lib.rs
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `tests/integration.rs:504` </location>
<code_context>
+}
+
+#[test]
+fn test_wrap_list_item() {
+    let input = vec![
+        "- This bullet item is exceptionally long and must be wrapped to keep \
</code_context>

<issue_to_address>
Add a test case for list items shorter than the wrap width.

Ensure that list items shorter than the wrap width are tested to confirm they remain unwrapped and retain their prefix and content on a single line.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/integration.rs
coderabbitai Bot added a commit that referenced this pull request Jun 15, 2025
…columns`

Docstrings generation was requested by @leynos.

* #32 (comment)

The following files were modified:

* `src/html.rs`
* `src/lib.rs`
* `tests/integration.rs`
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 15, 2025

Note

Generated docstrings for this pull request at #35

…columns` (#35)

Docstrings generation was requested by @leynos.

* #32 (comment)

The following files were modified:

* `src/html.rs`
* `src/lib.rs`
* `tests/integration.rs`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

1 participant