The sytnax highlighter is a MyBB plugin. And its in js and php. If anyone wants to poke around have at it.
The python brush is defined by regex
/inc/plugins/syntax/scripts/shBrush_python.js
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
function Brush()
{
// Contributed by Gheorghe Milas and Ahmad Sherif
var keywords = 'and assert break class continue def del elif else ' +
'except exec finally for from global if import in is ' +
'lambda not or pass print raise return try yield while';
var funcs = '__import__ abs all any apply basestring bin bool buffer callable ' +
'chr classmethod cmp coerce compile complex delattr dict dir ' +
'divmod enumerate eval execfile file filter float format frozenset ' +
'getattr globals hasattr hash help hex id input int intern ' +
'isinstance issubclass iter len list locals long map max min next ' +
'object oct open ord pow print property range raw_input reduce ' +
'reload repr reversed round set setattr slice sorted staticmethod ' +
'str sum super tuple type type unichr unicode vars xrange zip';
var special = 'None True False self cls class_';
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
{ regex: /^\s*@\w+/gm, css: 'decorator' },
{ regex: /(['\"]{3})([^\1])*?\1/gm, css: 'comments' },
{ regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm, css: 'string' },
{ regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm, css: 'string' },
{ regex: /\+|\-|\*|\/|\%|=|==/gm, css: 'keyword' },
{ regex: /\b\d+\.?\w*/g, css: 'value' },
{ regex: new RegExp(this.getKeywords(funcs), 'gmi'), css: 'functions' },
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' },
{ regex: new RegExp(this.getKeywords(special), 'gm'), css: 'color1' }
];
this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
};
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['py', 'python'];
SyntaxHighlighter.brushes.Python = Brush;
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();
/inc/plugins/mwsshcode.php
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
function mwsshcode_info() {
return array(
"name" => "MWS Syntax Highlighter",
"description" => "[shcode=python][/shcode] SyntaxHighlighter is an open source Java Script client side code syntax highlighter..",
"website" => "http://alexgorbatchev.com/SyntaxHighlighter/",
"author" => "MaRZoCHi",
"authorsite" => "http://www.marzochi.ws",
"version" => "1.1",
"compatibility" => "14*,16*,18*",
"guid" => "8036c90522d8e7d1b30caa08b218c2e7"
);
}
$plugins->add_hook("parse_message", "mwsshcode_run");
function mwsshcode_activate() {
global $db;
$insertarray = array(
'name' => 'mwsshcode',
'title' => 'MWS Syntax Highlighter',
'description' => "Full settings of Syntax Highlighter.",
'disporder' => 100,
'isdefault' => 0
);
$gid = $db->insert_query("settinggroups", $insertarray);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_enabled",
"title" => "Active?",
"description" => "Activate Plugin?",
"optionscode" => "yesno",
"value" => 2,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_auto-links",
"title" => "Automatic Links",
"description" => "Allows you to turn detection of links in the highlighted element on and off. If the option is turned off, URLs won’t be clickable",
"optionscode" => "yesno",
"value" => 2,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_gutter",
"title" => "Gutter Style",
"description" => "Allows you to turn gutter with line numbers on and off.",
"optionscode" => "yesno",
"value" => 1,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_theme",
"title" => "Higlight Theme",
"description" => "SyntaxHighlighter introduced custom CSS themes.Select your theme",
"optionscode" => "radio
Default=Default
Django=Django
Eclipse=Eclipse
Emacs=Emacs
FadeToGrey=FadeToGrey
MDUltra=MDUltra
Midnight=Midnight
RDark=RDark",
"value" => "Default",
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_smart-tabs",
"title" => "Smart Tbas",
"description" => "Allows you to turn smart tabs feature on and off",
"optionscode" => "yesno",
"value" => 1,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_tab-size",
"title" => "Smart Tab Size",
"description" => "Allows you to adjust tab size",
"optionscode" => "text",
"value" => 4,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_toolbar",
"title" => "Show Toolbar",
"description" => "Toggles toolbar on/off",
"optionscode" => "yesno",
"value" => 0,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_class-name",
"title" => "Extra Style Class",
"description" => "Enter Custom CSS class name for applying to code area",
"optionscode" => "text",
"value" => "",
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
$setting = array(
"sid" => NULL,
"name" => "mwsshcode_first-line",
"title" => "First-Line Number",
"description" => "Allows you to change the first (starting) line number",
"optionscode" => "text",
"value" => 1,
"disporder" => 2,
"gid" => $gid
);
$db->insert_query("settings", $setting);
rebuild_settings();
}
global $ins_count;
$ins_count = 0;
function insert_template_codes() {
global $mybb,$ins_count;
if ($ins_count == 0) {
$shcode = "<!-- start: mws_shcode -->\n";
$shcode .= "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$mybb->settings['bburl']}/inc/plugins/syntax/styles/shCore{$mybb->settings['mwsshcode_theme']}.css\">\n<script src=\"{$mybb->settings['bburl']}/inc/plugins/syntax/scripts/shCore.js\" type=\"text/javascript\"></script>\n<script type=\"text/javascript\">";
$shcode .= "\n\tSyntaxHighlighter.defaults['toolbar'] = {$mybb->settings['mwsshcode_toolbar']};";
$shcode .= "\n\tSyntaxHighlighter.defaults['first-line'] = {$mybb->settings['mwsshcode_first-line']};";
$shcode .= "\n\tSyntaxHighlighter.defaults['tab-size'] = {$mybb->settings['mwsshcode_tab-size']};";
$shcode .= "\n\tSyntaxHighlighter.defaults['smart-tabs'] = {$mybb->settings['mwsshcode_smart-tabs']};";
$shcode .= "\n\tSyntaxHighlighter.defaults['auto-links'] = {$mybb->settings['mwsshcode_auto-links']};";
$shcode .= "\n\tSyntaxHighlighter.defaults['guttter'] = {$mybb->settings['mwsshcode_gutter']};";
$shcode .= "\n\tSyntaxHighlighter.all();";
$shcode .= "\n</script>\n";
$shcode .= "<!-- end: mws_shcode -->";
$GLOBALS['headerinclude'] .= $shcode ;
$ins_count = 1;
}
}
function mwsshcode_deactivate() {
global $db;
$db->delete_query("settinggroups", "name = 'mwsshcode'");
rebuild_settings();
}
function mwsshcode_check($brush,$text) {
global $mybb;
insert_template_codes();
$text = preg_replace("/\<a href=\"(.*?)\"(.*?)>(.*?)\<\/a\>/si","\\3",$text);
$text = str_replace ( "\n", "
", $text);
$sstart = "";
$sfinish = "";
if (!empty($mybb->settings['mwsshcode_class-name'])) {
$sstart = "<div class=\"{$mybb->settings['mwsshcode_class-name']}\">";
$sfinish = "</div>";
}
return "<script type=\"text/javascript\" src=\"{$mybb->settings['bburl']}/inc/plugins/syntax/scripts/shBrush_{$brush}.js\"></script>{$sstart}<pre class=\"brush: {$brush};\">{$text}</pre>{$sfinish}";
}
function mwsshcode_run($content) {
global $mybb;
if ($mybb->settings['mwsshcode_enabled']) {
$content = preg_replace("/\[shcode\=(.+?)\](.*?)\[\/shcode\]/ies", '"".mwsshcode_check("$1","$2").""', $content);
}
return $content;
}
?>