int main (void){
printf("This is some random code");
return 0;
} [/highlight]
Normally the file extension can be used for the lang parameter (like pl, py, java, pas etc).
Execute 'highlight --list-langs' to get a list of all supported programming langauges.
== Installation ==
1. Install the highlight utility on your host (www.andre-simon.de)
2. Copy the serendipity_event_highlight dir into the serendipity plugin dir
3. Activate and configure the plugin in the serendipity administration menu
IMPORTANT:
To avoid insertion of superfluous
Tags by the nl2br plugin, add the
string "highlight" to the "list of HTML-tags where no breaks shall be
converted" in the nl2br configuration menu.
*/
if (IN_serendipity !== true) {
die ("Don't hack!");
}
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
class serendipity_event_highlight extends serendipity_event
{
var $title = PLUGIN_EVENT_HIGHLIGHT_NAME;
// Top Level Configuration, requires name of the Plugin, description text, and configuration information in an array..
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_NAME);
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Andre Simon');
$propbag->add('requirements', array(
'serendipity' => '0.9',
'highlight' => '2.6.4'
));
$propbag->add('version', '0.1');
$propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
$propbag->add('groups', array('MARKUP'));
$this->markup_elements = array(
array(
'name' => 'ENTRY_BODY',
'element' => 'body',
),
array(
'name' => 'EXTENDED_BODY',
'element' => 'extended',
),
array(
'name' => 'COMMENT',
'element' => 'comment',
),
array(
'name' => 'HTML_NUGGET',
'element' => 'html_nugget',
)
);
#Colour themes of a highlight default installation
$this->themes = array(
"acid", "bipolar", "blacknblue", "bright", "contrast", "darkblue", "darkness", "desert", "dull", "easter", "emacs", "golden", "greenlcd",
"ide-anjuta", "ide-codewarrior", "ide-devcpp", "ide-eclipse", "ide-kdev", "ide-msvcpp", "ide-xcode", "kwrite", "lucretia", "matlab", "navy",
"nedit", "neon", "night", "orion", "pablo", "peachpuff", "print", "rand01", "seashell", "the", "typical", "vampire", "vim-dark", "vim",
"whitengrey", "zellner"
);
#Reformatting schemes of a highlight default installation
$this->reformatschemes = array ("disabled","ansi", "gnu", "java", "kr", "linux");
#highlight output options
$conf_array = array('hl_bin_dir','hl_data_dir','hl_linenumbers','hl_linenumberstart','hl_linenumberzeroes','hl_linenumberlen',
'hl_wrap','hl_wrap_len','hl_tab_len', 'hl_theme','hl_format');
foreach($this->markup_elements as $element) {
$conf_array[] = $element['name'];
}
$propbag->add('configuration', $conf_array);
}
function generate_content(&$title) {
$title = $this->title;
}
function introspect_config_item($name, &$propbag) {
switch ($name) {
case 'hl_bin_dir' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_HLBINDIR);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_HLBINDIR_DESC);
$propbag->add('default', 'highlight');
break;
case 'hl_data_dir' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_HLDATADIR);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_HLDATADIR_DESC);
$propbag->add('default', '/usr/share/highlight/');
break;
case 'hl_linenumbers' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS);
$propbag->add('type', 'boolean');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS_DESC);
$propbag->add('default', 'false');
break;
case 'hl_linenumberzeroes' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES);
$propbag->add('type', 'boolean');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES_DESC);
$propbag->add('default', 'false');
break;
case 'hl_linenumberstart' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART_DESC);
$propbag->add('default', '1');
$propbag->add('validate', 'number');
break;
case 'hl_linenumberlen' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN_DESC);
$propbag->add('default', '2');
$propbag->add('validate', 'number');
break;
case 'hl_theme' :
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_THEMES);
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_THEMES_DESC);
$propbag->add('select_values', $this->themes);
$propbag->add('default', '1');
break;
case 'hl_format' :
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_FORMAT);
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_FORMAT_DESC);
$propbag->add('select_values', $this->reformatschemes);
$propbag->add('default', '0');
break;
case 'hl_wrap' :
$wrapstyles=array ('No wrap', 'Simple wrap','Intelligent wrap');
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_WRAP);
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_WRAP_DESC);
$propbag->add('select_values', $wrapstyles);
$propbag->add('default', '0');
break;
case 'hl_wrap_len' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_WRAPLEN);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_WRAPLEN_DESC);
$propbag->add('default', '60');
$propbag->add('validate', 'number');
break;
case 'hl_tab_len' :
$propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_TABLEN);
$propbag->add('type', 'string');
$propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_TABLEN_DESC);
$propbag->add('default', '4');
$propbag->add('validate', 'number');
break;
default :
$propbag->add('name', constant($name));
$propbag->add('type', 'boolean');
$propbag->add('default', 'true');
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
}
return true;
}
function geshi($input) {
$input = preg_replace_callback('/\[highlight(?:\s)*lang=([A-Za-z0-9_\-]+)(?:\s)*()?\](.*?)\[\/highlight\]/si', array(&$this, 'highlightcallback'), $input);
return $input;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
foreach ($this->markup_elements as $temp) {
if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
!$eventData['properties']['ep_disable_markup_' . $this->instance] &&
!isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
$element = $temp['element'];
$eventData[$element] = $this->geshi($eventData[$element]);
}
}
return true;
break;
case 'frontend_comment':
if (serendipity_db_bool($this->get_config('COMMENT', true))) {
echo '
"; $result .= $input_code; $result .= ""; } else { $result .= "
"; $result .= $output; $result .= ""; } return $result; } } ?>