Highlighting Special Lines “Extra” - GeSHi/geshi-1.0 GitHub Wiki

The stable method of highlighting code that is important is to use extra highlighting by line. Although you may not know what line numbers contain the important lines, if you do this method is a much more flexible way of making important lines stand out.

Specifying the Lines to Highlight Extra

To specify which lines to highlight extra, you pass an array containing the line numbers to highlight_lines_extra():


The array could be in the form array(2, 3, 4, 7, 12, 344, 4242), made from a DB query, generated from looking through the source for certain important things and working out what line those things are… However you get the line numbers, the array should simply be an array of integers.

Here’s an example, using the same source as before:

// Here we go again! This time we'll simply highlight the 8th line
$source = 'public int[][] product ( n, m )
  int [][] ans = new int[n][m];
  for ( int i = 0; i < n; i++ )
    for ( int j = 0; i < m; j++ )
      ans[i][j] = i * j;
  return ans;
$geshi = new GeSHi($source, 'java');
echo $geshi->parse_code();

Which produces:

FIXME a screenshot would be needed here

What’s more, as you can see the code on a highlighted line is still actually highlighted itself.

Styles for the Highlighted Lines

Again as with contextual importance, you’re not chained to the yellow theme that is the default. You can use the set_highlight_lines_extra_style method:


Where $styles is the stylesheet declarations that you want to apply to highlighted lines.