gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Line Break support for Excerpt

Open JulienGardair opened this issue 2 years ago • 2 comments

Would it be possible to add Line Break support for the excerpt? At least for the manual excerpt?

Funny test, The Block Excerpt shows line breaks (no HTMLtag just [enter] in the manual excerpt) when displayed outside the Query Loop on a test post editor but not on the front end, neither within the Query Loop Block in the post editor.

WP 6.4.3 Gutenberg 17.9.0

JulienGardair avatar Mar 15 '24 14:03 JulienGardair

Thanks for sharing the issue,

Adding a screencast to showcase the issue better

https://github.com/user-attachments/assets/9a9ec507-76f4-4f0d-a30d-be8281ec0aea

Rishit30G avatar May 27 '25 05:05 Rishit30G

Thanks for reporting this!

It looks like the newline characters (\n) are removed due to the use of wp_trim_words() in the block's server-side render callback. It strips all types of whitespace, including newlines, during the word trimming process.

To preserve newline characters while still respecting the configured word limit, we may need to modify or override the implementation of wp_trim_words() within the block logic, and then convert the preserved newline characters into line breaks (<br>) for display.

I'll explore a potential patch to improve this behavior and will raise a PR once it's ready. Let me know if I’ve missed anything or if there’s a preferred way to approach this.

BugReportOnWeb avatar Jun 17 '25 18:06 BugReportOnWeb