Index: api.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/api/api.css,v retrieving revision 1.15.2.2 diff -u -p -r1.15.2.2 api.css --- api.css 28 Jan 2009 21:05:03 -0000 1.15.2.2 +++ api.css 6 Jun 2009 01:04:13 -0000 @@ -37,6 +37,10 @@ html.js div.api-expandable div.content { color: #060; } +.line-count { + color: #aaa; +} + /* Lists */ dl.api-related-topics dt { clear: both; Index: parser.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/api/parser.inc,v retrieving revision 1.41.2.1 diff -u -p -r1.41.2.1 parser.inc --- parser.inc 28 Jan 2009 21:35:50 -0000 1.41.2.1 +++ parser.inc 6 Jun 2009 01:04:13 -0000 @@ -598,8 +598,6 @@ function api_documentation_summary($docu * Colorize and format a PHP script. */ function api_format_php($code) { - $output = ''; - if (!defined('T_ML_COMMENT')) { define('T_ML_COMMENT', T_COMMENT); } @@ -610,6 +608,8 @@ function api_format_php($code) { $tokens = token_get_all($code); $in_string = FALSE; + $output = _api_format_php_line_count_format(1); + $line_count = 2; foreach ($tokens as $token) { if ($in_string) { @@ -631,6 +631,7 @@ function api_format_php($code) { if (is_array($token)) { $type = $token[0]; $value = htmlspecialchars($token[1]); + _api_format_php_line_count($value, $line_count); switch ($type) { case T_OPEN_TAG: @@ -688,7 +689,25 @@ function api_format_php($code) { } // Manage whitespace: - return '
'. trim($output) .'
'; + return '
'. $output .'
'; +} + +/** + * Insert line numbers where line breaks occur in code. + */ +function _api_format_php_line_count(&$code, &$line_count) { + $pos = 0; + while (($pos = strpos($code, PHP_EOL, $pos)) !== FALSE) { + $code = substr($code, 0, ++$pos) . _api_format_php_line_count_format($line_count, $pos) . substr($code, $pos++); + $line_count++; + } +} + +/** + * Format a line number into a string + */ +function _api_format_php_line_count_format($line_count) { + return '' . str_pad($line_count, 4, " ", STR_PAD_LEFT) . '. '; } /**