TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.51k stars 10.37k forks source link

Excerpt and plaintext fields add extra new lines #14255

Closed Marky-Gee closed 2 years ago

Marky-Gee commented 2 years ago

Issue Summary

When a post is created, the excerpt and plaintext fields in the content API and webhooks add extra newlines where they are not needed.

Typing the sentence "For creators and aspiring entrepreneurs looking to generate a sustainable recurring revenue stream from their creative work, Ghost has built-in payments allowing you to create a subscription commerce business." in the editor produces.

HTML Produces (Correct) <p>For creators and aspiring entrepreneurs looking to generate a sustainable recurring revenue stream from their creative work, Ghost has built-in payments allowing you to create a subscription commerce business.</p>

Plaintext produces (new lines after "sustainable" & "payments" Incorrect)

For creators and aspiring entrepreneurs looking to generate a sustainable
recurring revenue stream from their creative work, Ghost has built-in payments
allowing you to create a subscription commerce business.

Steps to Reproduce

  1. Create a new post
  2. Copy the following 2 paragraphs
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vehicula nulla eget hendrerit vehicula. Sed et dui lacus. Suspendisse elementum mi quam, ut fringilla diam varius et. Nunc pretium ligula finibus massa iaculis interdum. Sed ligula mi, consequat consequat molestie nec, scelerisque at nisl. Donec vel sagittis diam, in sollicitudin est. Suspendisse volutpat sollicitudin ultricies. Nulla eget enim quis elit luctus tempus. Donec convallis magna quis tellus varius volutpat.

Ut semper sit amet tortor non auctor. Praesent leo tellus, efficitur et tortor in, commodo lacinia eros. Morbi tincidunt enim ac sem ultricies, sit amet convallis nisl posuere. Aliquam imperdiet felis sit amet justo tincidunt, in dapibus odio laoreet. Phasellus vehicula nibh risus, vel viverra lacus gravida nec. Nam velit elit, efficitur at leo non, auctor feugiat arcu. Nulla volutpat in tellus vitae gravida. Fusce vehicula mi at dictum posuere. Vestibulum ac quam iaculis, luctus nisi et, volutpat dolor. Sed placerat sit amet magna nec lobortis. Maecenas ultricies, felis ut tincidunt sagittis, quam lorem iaculis tellus, in blandit arcu nulla a magna.


3. Save and publish
4. Check either the excerpt and plaintext to find 
`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vehicula nulla\neget hendrerit vehicula. Sed et dui lacus. Suspendisse elementum mi quam, ut\nfringilla diam varius et. Nunc pretium ligula finibus massa iaculis interdum.\nSed ligula mi, consequat consequat molestie nec, scelerisque at nisl. Donec vel\nsagittis diam, in sollicitudin est. Suspendisse volutpat sollicitudin ultricies.\nNulla eget enim quis elit luctus tempus. Donec convallis magna quis tellus\nvarius volutpat.\n\nUt semper sit amet tortor non auctor. Praesent leo tellus, efficitur et tortor\nin, commodo lacinia eros. Morbi tincidunt enim ac sem ultricies, sit amet\nconvallis nisl posuere. Aliquam imperdiet felis sit amet justo tincidunt, in\ndapibus odio laoreet. Phasellus vehicula nibh risus, vel viverra lacus gravida\nnec. Nam velit elit, efficitur at leo non, auctor feugiat arcu. Nulla volutpat\nin tellus vitae gravida. Fusce vehicula mi at dictum posuere. Vestibulum ac quam\niaculis, luctus nisi et, volutpat dolor. Sed placerat sit amet magna nec\nlobortis. Maecenas ultricies, felis ut tincidunt sagittis, quam lorem iaculis\ntellus, in blandit arcu nulla a magna.`

### Ghost Version

4.37, 3.35 (and likely the rand between)

### Node.js Version

14.x

### How did you install Ghost?

ubuntu, followed instructions on web

### Database type

Other

### Browser & OS version

Chrome

### Relevant log / error output

_No response_

### Code of Conduct

- [X] I agree to be friendly and polite to people in this repository
Marky-Gee commented 2 years ago

Actually I've found the file https://github.com/TryGhost/Ghost/blob/main/core/shared/html-to-plaintext.js which includes the wordwrap: 80 that was causing my issue.

So this isn't really a bug, just something I didn't think was done on purpose.

You can close this if you wish.

ErisDS commented 2 years ago

The original intention for the plaintext field was as the text version of the post in an email. It ended up being used for excerpts, and actually we generate the email text elsewhere.

This is one of many problems which can be summarised as "our automatic excerpts are rubbish" 😬 but it's not yet reached the point where anyone cares enough to come up with a smarter version... not least because changing this outside a major version would be unexpected IMO.

It's something we'll consider revisiting in the next major (it's on the list) but otherwise I'm going to close this as it only represents a tiny fraction of the problem! πŸ™ˆ πŸ™ˆ πŸ™ˆ