PHPBB3-11742 - BBCode 'code' doesn't support tabs / whitespace improvements

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.2/Rhea branch. Everything listed in this forum will be available in phpBB 3.2.
Post Reply
User avatar
JoshyPHP
Registered User
Posts: 381
Joined: Fri Jul 08, 2011 9:43 pm

PHPBB3-11742 - BBCode 'code' doesn't support tabs / whitespace improvements

Post by JoshyPHP »

https://tracker.phpbb.com/browse/PHPBB3-11742
https://github.com/phpbb/phpbb/pull/3625

The code BBCode doesn't really support tabs. It actually replaces them with a mix of spaces and &nbsp;. The obvious fix is to wrap the code block in a <pre> block. Inside <pre>, new lines are preserved and line breaks are unnecessary. Also, <pre> doesn't produce a blank line for the first line of the block. However, <pre><code> does. That means this:

Code: Select all

[cοde]
line 1
line 2
[/cοde]
...becomes this:

Code: Select all

<pre><code>
line 1
line 2
</code></pre>
...which looks like this:
phpbb-code.png
Possible solutions include not using a <code> element, or manually removing the first blank line from code blocks in PHP. Does anybody have a better idea?

User avatar
MattF
Extension Customisations
Extension Customisations
Posts: 675
Joined: Mon Mar 08, 2010 9:18 am

Re: PHPBB3-11742 - BBCode 'code' doesn't support tabs / whitespace improvements

Post by MattF »

I'm not getting that extra line at the start when wrapping code in pre like <pre><code>. Anyway this was solved long ago by a MOD https://www.phpbb.com/customise/db/mod/ ... ancements/
I'd look at what that MOD does.
Screen Shot 2015-05-24 at 10.44.08 PM.png
Has an irascible disposition.

User avatar
JoshyPHP
Registered User
Posts: 381
Joined: Fri Jul 08, 2011 9:43 pm

Re: PHPBB3-11742 - BBCode 'code' doesn't support tabs / whitespace improvements

Post by JoshyPHP »

I ended up solving it in the library by removing the first character from the code block if it's a newline. That's why your code block doesn't have it.

That MOD uses pre without code, that's why it doesn't have a blank line at the start.

Post Reply