wordpress-activitypub icon indicating copy to clipboard operation
wordpress-activitypub copied to clipboard

Strip whitespace between HTML tags instead of all content

Open pfefferle opened this issue 4 weeks ago • 1 comments

Fixes #2592 Supersedes #2595

Proposed changes:

  • Add Sanitize::strip_whitespace() method that only removes newlines, carriage returns, and tabs between HTML tags (/>[\n\r\t]+</) rather than stripping them from all content.
  • This preserves whitespace inside preformatted elements like <pre> and <code> blocks without needing special handling.
  • Update Shortcodes::content() to use the new sanitization method.
  • Remove redundant wpautop() and whitespace stripping from Post::get_content() since content is already processed.

Other information:

  • [x] Have you written new tests for your changes, if applicable?

Testing instructions:

  1. Create a post with a code block containing multiple lines
  2. Publish the post
  3. View the federated content on a remote instance (or inspect the ActivityPub JSON at /wp-json/activitypub/1.0/posts/{id})
  4. Verify the code block preserves newlines and formatting

Changelog entry

  • [x] Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • [x] Patch
  • [ ] Minor
  • [ ] Major

Type

  • [ ] Added - for new features
  • [ ] Changed - for changes in existing functionality
  • [ ] Deprecated - for soon-to-be removed features
  • [ ] Removed - for now removed features
  • [x] Fixed - for any bug fixes
  • [ ] Security - in case of vulnerabilities

Message

Preserve whitespace inside preformatted elements when federating content.

pfefferle avatar Dec 11 '25 14:12 pfefferle

Is this ready for review?

obenland avatar Dec 11 '25 15:12 obenland

@obenland Seems to work like expected

Screenshot 2025-12-15 at 12 50 38

pfefferle avatar Dec 15 '25 11:12 pfefferle