Skip to content

Post list preview: trim trailing newline in generated excerpt#25349

Open
YuF-9468 wants to merge 2 commits intowordpress-mobile:trunkfrom
YuF-9468:fix-12673-trim-preview-newlines
Open

Post list preview: trim trailing newline in generated excerpt#25349
YuF-9468 wants to merge 2 commits intowordpress-mobile:trunkfrom
YuF-9468:fix-12673-trim-preview-newlines

Conversation

@YuF-9468
Copy link

@YuF-9468 YuF-9468 commented Mar 5, 2026

Description

Fixes #12673.

This updates post preview generation to trim leading/trailing whitespace and newlines after extracting/collapsing preview text. It prevents preview labels from rendering a trailing blank line in the post list when content contains paragraph separators.

Testing instructions

  1. Create or edit a post with multiple paragraph blocks.
  2. Return to the post list.
  3. Verify the preview no longer shows an extra blank trailing line/empty space under the first visible line.

Automated verification

  • Added testThatContentPreviewForDisplayTrimsLeadingAndTrailingNewlines in PostTests.
  • CI should run the updated test suite for this PR.

@jkmassel jkmassel self-assigned this Mar 6, 2026
Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this! The implementation looks good, I just left a note about improving one test.

I appreciate the contribution, and I'm excited to get it merged!

@YuF-9468
Copy link
Author

YuF-9468 commented Mar 7, 2026

Great call — updated ✅

I changed the test to assert the explicit expected output instead of mirroring implementation details:

  • XCTAssertEqual("Paragraph 1\nParagraph 2", preview)

Commit: 9f5831e

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 7, 2026

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.

Gutenberg paragraph shows up as an empty space in Post List

3 participants