MyBB Community Forums

Full Version: Embedded videos have extraneous vertical space above and below
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Members of the MyBB-powered forum I help administer have complained that embedded videos have extra spaces inserted above and below them after the post is submitted. I had noticed this issue too. I fixed it on our forum by adding second (value: 1) and third (value: 0) parameters to the call $templates->get("video_{$video}_embed") in the eval() on the second-to-last line of postParser::mycode_parse_video() in inc/class_parser.php.

It's the third parameter that fixes the problem (the second is simply the  default), by omitting comments from the eval()d template. When comments are inserted, along with them are inserted a newline above and a newline below the embedded video, and these are ultimately converted into <br>s by the call to nl2br() in postParser::parse_message(), resulting in the complained-about extra spaces.

These extra parameters are present in all other calls to $templates->get() in the parser, so perhaps their omission here was just a minor oversight.
I cannot reproduce this. It looks fine to me. Screenshot.
Here's a demo on this forum then. Because of the 1-video-per-message limitation, I'll have to do it in four posts. First, the code for the first test:

Test1.[video=youtube]https://www.youtube.com/watch?v=E1fzJ_AYajA[/video]Test2.

This is rendered as:

Test1.Test2.

Notice the break after "Test1" and before "Test2" - these should be inline with the video and are inline with it in the visual editor.

The code for the second test:

Test1.
[video=youtube]https://www.youtube.com/watch?v=E1fzJ_AYajA[/video]
Test2.

This is rendered as:

Test1.

Test2.

Notice the spaces between "Test1" and "Test2" above and below the video - these spaces shouldn't be there and aren't there in the visual editor.
I see the generated output is logical and perfect rather than a bug.
You place line break in your code and the same is being carried to the output.
(2018-07-04, 03:06 AM)effone Wrote: [ -> ]I see the generated output is logical and perfect rather than a bug.
You place line break in your code and the same is being carried to the output.

No, I place a line break in my code and two line breaks are carried to the output (second test).

And when I don't place a line break in my code, I get one anyway (first test).

If you view the source of this thread you can see that the embedded videos are being rendered with this HTML:

<!-- start: video_youtube_embed --><br />
<iframe width="560" height="315" src="//www.youtube.com/embed/E1fzJ_AYajA" frameborder="0" allowfullscreen></iframe><br />
<!-- end: video_youtube_embed -->

There you can see the two extra <br>s: one after the start comment and before the second comment.
This is the preferred way (as it is) IMO.
SCeditor is really mysterious, I am looking forward to MyBB v1.9 - it will be replaced by another (and much better) one Smile
I would consider this as unintended behaviour personally, as all other templates in the parser are loaded with the 3rd parameter to "$templates->get()" set to 1 such as:

https://github.com/mybb/mybb/blob/featur...r.php#L731
https://github.com/mybb/mybb/blob/featur...r.php#L552

The only call that doesn't set the parameters as such is when rendering a video: https://github.com/mybb/mybb/blob/featur....php#L1498

If videos should have whitespace wrapping them, IMO that should be done in the video templates themselves.
Thank you, Euan. Agreed. And I don't see why videos should have whitespace wrapping them (and by the way, I'm not saying this is your view, because you haven't stated one). Wouldn't that be making them a special case, and if so, what would justify that special case? In any event, if it were to be done, it would (continue to) conflict with the rendering of videos in the visual editor, so at the very least there's an issue with respect to that conflict.
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/3340

Thanks for contributing to MyBB!

Regards,
The MyBB Group