Case Sensitivity and Auto Casing - GeSHi/geshi-1.0 GitHub Wiki

Controlling the case of the outputted source is an easy job with GeSHi. You can control which keywords are converted in case, and also control whether keywords are checked in a case sensitive manner.

Auto-Caps/NoCaps

Auto-Caps/NoCaps is a nifty little feature that capitalises or lowercases automatically certain lexics when they are styled. I dabble in QuickBASIC, a dialect of BASIC which is well known for it’s capatalisation, and SQL is another language well known for using caps for readability.

To change what case lexics are rendered in, you call the set_case_keywords() method:

$geshi->set_case_keywords($caps_modifier);

The valid values to pass to this method are:

  • GESHI_CAPS_NO_CHANGE - Don’t change the case of any lexics, leave as they are found
  • GESHI_CAPS_UPPER - Uppercase all lexics found
  • GESHI_CAPS_LOWER - Lowercase all lexics found

:exclamation: Caution:

When I say “lexic”, I mean “keywords”. Any keyword in any keyword array will be modified using this option! This is one small area of inflexibility I hope to fix in 1.2.X.

I suspect this will only be used to specify GESHI_CAPS_NO_CHANGE to turn off autocaps for languages like SQL and BASIC variants, like so:

$geshi = new GeSHi($source, 'sql');
$geshi->set_case_keywords(GESHI_CAPS_NO_CHANGE); // don't want keywords capatalised

All the same, it can be used for some interesting effects:

$geshi = new GeSHi($source, 'java');
// Anyone who's used java knows how picky it is about CapitalLetters...
$geshi->set_case_keywords(GESHI_CAPS_LOWER);
// No *way* the source will look right now ;)

Setting Case Sensitivity

Some languages, like PHP, don’t mind what case function names and keywords are in, while others, like Java, depend on such pickiness to maintain their bad reputations ;). In any event, you can use the set_case_sensitivity() to change the case sensitiveness of a particular keyword group from the default:

$geshi->set_case_sensitivity($key, $sensitivity);

Where $key is the key of the group for which you wish to change case sensitivness for (see the language file for that language), and $sensitivity is a boolean value - true if the keyword is case sensitive, and false if not.