Bug tracker

This ticket has been moved to our new tracker. Open Ticket PHPBB3-7222 now.

issues with the [code] BBCode (fix completed in vcs)

As currently implemented, the [ code] BBCode seems to be of limited usefulness.

Say you're trying to copy / paste some code written to confirm to a certain coding standard that uses tabs to indent. With the current [ code] tag, each tab gets converted to spaces, so you'll have to do some post-processing on the text that you get back to make it be formatted correctly.

Also, in Firefox, if you hit the "Select all" link, there are four spaces pre-pended to each line in the text.

The following seems sufficient to fix it (and also serves as a demonstration of the problem since it's in a [ code] tag):

Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/bbcode.html
#
#-----[ FIND ]------------------------------------------
#
<!-- BEGIN code_open --><dl class="codebox"><dt>{L_CODE}: <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></dt><dd><code><!-- END code_open -->
<!-- BEGIN code_close --></code></dd></dl><!-- END code_close -->
#
#-----[ REPLACE WITH ]----------------------------------
#
<!-- BEGIN code_open --><dl class="codebox"><dt>{L_CODE}: <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></dt><dd><code><pre><!-- END code_open -->
<!-- BEGIN code_close --></pre></code></dd></dl><!-- END code_close -->
#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/forum_fn.js
#
#-----[ FIND ]------------------------------------------
#
   var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
#
#-----[ REPLACE WITH ]----------------------------------
#
   var e = a.parentNode.parentNode.getElementsByTagName('PRE')[0];
#
#-----[ OPEN ]------------------------------------------
#
includes/bbcode.php
#
#-----[ FIND ]------------------------------------------
#
      switch ($type)
      {
         case 'php':
            // Not the english way, but valid because of hardcoded syntax highlighting
            if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
            {
               $code = substr($code, 41);
            }

         // no break;

         default:
            $code = str_replace("\t", '&nbsp; &nbsp;', $code);
            $code = str_replace('  ', '&nbsp; ', $code);
            $code = str_replace('  ', ' &nbsp;', $code);

            // remove newline at the beginning
            if (!empty($code) && $code[0] == "\n")
            {
               $code = substr($code, 1);
            }
         break;
      }
#
#-----[ REPLACE WITH ]----------------------------------
#
      if ($type == 'php' && strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
      {
         $code = substr($code, 41);
      }

By using the <pre> html tag, I eliminate the need to convert white space over with nbsp and the regular sp. This also seems to eliminate the whole four spaces pre-pended issue in Firefox.

Comments / History

Posted by Kellanved (Former Team Member) on Apr 14th 2008, 10:27

Pre is not valid XHTML.

Posted by TerraFrost (Former Team Member) on Apr 14th 2008, 13:11

Pages with pre seem to validate just fine as XHTML 1.0 Strict:

http://validator.w3.org/check?uri=http% ... ne&group=0

In contrast, pages with u, which has been deprecated, don't:

http://validator.w3.org/check?uri=http% ... ne&group=0

Posted by Kellanved (Former Team Member) on Apr 14th 2008, 13:19

I stand corrected.

Posted by Schumi (QA Team) on Apr 14th 2008, 13:24

However, it doesn't validate in the context it gets displayed for me:
Line 216, Column 141: document type does not allow element "pre" here; missing one of "object", "ins", "del", "map", "button" start-tag.

…e;">Select all</a></dt><dd><code><pre>some code...</pre></code></dd></dl><br

Posted by TerraFrost (Former Team Member) on Apr 14th 2008, 15:10

Nice catch. Removing the <code> tags fix that. The CSS will also have to be updated:

Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/theme/content.css
#
#-----[ FIND ]------------------------------------------
#
dl.codebox pre {
   /* Also see tweaks.css */
   overflow: auto;
   display: block;
   height: auto;
   max-height: 200px;
   white-space: normal;
   padding-top: 5px;
   font: 0.9em Monaco, "Andale Mono","Courier New", Courier, mono;
   line-height: 1.3em;
   color: #8b8b8b;
   margin: 2px 0;
}
#
#-----[ REPLACE WITH ]----------------------------------
#
dl.codebox pre {
   /* Also see tweaks.css */
   overflow: auto;
   height: auto;
   max-height: 200px;
   padding-top: 5px;
   font: 0.9em Monaco, "Andale Mono","Courier New", Courier, mono;
   line-height: 1.3em;
   color: #8b8b8b;
   margin: 2px 0;
}

Posted by Acyd Burn (Server Manager) on Apr 21st 2008, 13:24

Not having tested it - but is the styler still having full freedom in laying it out? If we change it within the core, is there a noticeable difference within the style? (this should not happen, it should look exactly as it is now).

Assigned ticket to user "Acyd Burn"

Action performed by Acyd Burn (Server Manager) on Apr 21st 2008, 13:24

Posted by TerraFrost (Former Team Member) on Apr 21st 2008, 19:11

The appearance is pretty much the same as it was before and should be just as customisable. The only difference is that style authors may need to update their styles (I had to remove the white-space: normal thing, for instance).

Posted by 3Di on May 7th 2008, 22:13

Yes, already noticed here, once upon a time. http://www.phpbb.com/bugs/phpbb3/ticket ... et_id=8770

Linked ticket with changeset: r8893

Action performed by Anonymous (I am too lazy to register) on Sep 19th 2008, 16:40

Linked ticket with changeset: r8894

Action performed by Anonymous (I am too lazy to register) on Sep 19th 2008, 16:42

Changed ticket status from "New" to "Fix completed in SVN"

Action performed by Acyd Burn (Server Manager) on Sep 19th 2008, 16:43

Ticket details

Related SVN changesets