-
Notifications
You must be signed in to change notification settings - Fork 101
Using Strict Mode
Some languages like to get tricky, and jump in and out of the file that they’re in. For example, the vast majority of you reading this will have used a PHP file. And you know that PHP code is only executed if it’s within delimiters like <?php
and ?>
(there are others of course…). So what happens if you do the following in a php file?
<img src="<?php echo rand(1, 100) ?>" />
When using GeSHi without strict mode, or using a bad highlighter, you’ll end up with scrambled crap, especially if you’re being slack about where you’re putting your quotes, you could end up with the rest of your file as bright blue. Fortunately, you can tell GeSHi to be “strict” about just when it highlights and when it does not, using the enable_strict_mode()
method:
$geshi->enable_strict_mode($mode);
Where $mode
is true
or not specified to enable strict mode, or false
to disable strict mode if you’ve already turned it and don’t want it now.
👉 Note:
As of GeSHi 1.0.8 there is a new way to tell GeSHi when to use Strict Mode which is somewhat more intelligent than in previous releases. GeSHi now also allows
GESHI_MAYBE
,GESHI_NEVER
andGESHI_ALWAYS
instead oftrue
andfalse
. BasicallyGESHI_ALWAYS
(true
) always enables strict mode, whereasGESHI_NEVER
(false
) completely disables strict mode. The new thing isGESHI_MAYBE
which enables strict mode if it finds any sequences of code that look like strict block delimiters.By the way: That’s why this section had to be changed, as the new documentation tool we now use, applies this feature and thus auto-detects when strict mode has to be used…