akeeba / engage

Akeeba Engage - Comments for Joomla!™ articles made easy
GNU General Public License v3.0
16 stars 10 forks source link

Trim spaces from beginning / end of a comment? #298

Closed jjnxpct closed 9 months ago

jjnxpct commented 9 months ago

Might it be usefull to trim whitespaces from a new comment before saving it to the database? We see user adding whitespaces (probably unintentionally) to their comment. This does not xause big iusses, but it might be a good idea to clean it up before saving?

nikosdion commented 9 months ago

Oof. This is a can of worms. I would only consider it if we were taking input in something straightforward to parse, like Markdown.

HTML is… convoluted. Your spaces can't really be multiple space characters (0x20) as they do not appear as consecutive spaces in the output… unless you have CSS telling it otherwise. Now you start seeing a problem, right? How can we determine if multiple spaces even appear as such?

Or it could be non-breaking spaces. However, non-breaking spaces also have their place. You can't collapse them to regular space.

Speaking of, you can safely remove multiple spaces because you might indeed have preformatted output and it might not even be in a PRE, CODE, or TT tag.

It's also very likely that you have empty paragraphs, not spaces. That's even worse to work with especially since browsers consider </p> without an opening tag to define a valid paragraph. DIV can also do that, if it has an inline or global style which gives it height even when empty.

Basically, you'd need to implement a browser engine to determine what creates empty space and remove it.

I know of many ways to go insane. This is not even close to being one of my favourite ones. So I will go with no, will not implement.

jjnxpct commented 9 months ago

I knew you would think harder / further about this then me ;-) I get your point. Thanks for your clear response.

nikosdion commented 9 months ago

You're welcome and thank you for bringing this up :)

I had done this thinking three years ago when I was still designing the component. It was part of weighing the pros and cons of using the WYSIWYG editor versus using something like a Markdown editor. Ultimately, the worst abused can be dealt with the Joomla! text filters. Some edge cases, like yours, I decided we can live with. It's what we had to give up to have a pleasant editing experience. My observation is that people hate writing comments when the editing experience is not much better than a 1980s text terminal (phpBB, I am looking at you…).