Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-7222

issues with the [code] BBCode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 3.0.3
    • 3.0.1
    • Posting
    • None
    • PHP Environment:
      Database:

      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):

      #
      #-----[ 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.

            Acyd Burn Meik Sievertsen [X] (Inactive)
            TerraFrost TerraFrost [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: