PHP code line numbering

will.gresham - May 1, 2009 - 11:58
Project:Bbcode
Version:6.x-1.2
Component:Code
Category:feature request
Priority:minor
Assigned:will.gresham
Status:needs review
Description

I have put a little addition into the filter module to add line numbers to PHP code blocks.

It uses OL and LI tags to add the line numbers, replace the entire _bbcode_php_tag function with the one below:

function _bbcode_php_tag($text = NULL) {            
  $text_source = explode("\n", $text);
  foreach ($text_source as $this_line)
  {
      $output_code .= '<li>';
   
      if (ereg('<\?(php)?[^[:graph:]]', $this_line))
          $output_code .= str_replace(array('<code>', '
', "\n", '
'), '', highlight_string($this_line, true)) . '

';
else
$output_code .= ereg_replace('(<\?php )+', '', str_replace(array('', '', "\n", '
'), '', highlight_string('<?php '.$this_line, true))) . '

';
}
$return = '

    '.$output_code.'

';
return $return;
}

This can probable be scaled down a bit, but it works for my needs.

#1

will.gresham - May 1, 2009 - 12:10

I seem to have broken the drupal filter...

I have attached the script for you:

AttachmentSize
php_code_update.php.txt 722 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.