Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax highlighting
#7
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;
}
?>
Recommended Tutorials:
Reply


Messages In This Thread
syntax highlighting - by metulburr - Sep-05-2016, 12:32 AM
RE: syntax highlighting - by snippsat - Sep-07-2016, 06:29 PM
RE: syntax highlighting - by metulburr - Sep-07-2016, 09:25 PM
RE: syntax highlighting - by snippsat - Sep-08-2016, 09:33 AM
RE: syntax highlighting - by metulburr - Sep-08-2016, 11:54 AM
RE: syntax highlighting - by ichabod801 - Sep-14-2016, 11:24 PM
RE: syntax highlighting - by metulburr - Sep-15-2016, 12:25 AM
RE: syntax highlighting - by snippsat - Sep-15-2016, 04:29 PM
RE: syntax highlighting - by metulburr - Sep-15-2016, 05:18 PM
RE: syntax highlighting - by metulburr - Sep-15-2016, 05:25 PM
RE: syntax highlighting - by snippsat - Sep-15-2016, 06:07 PM
RE: syntax highlighting - by metulburr - Sep-15-2016, 06:44 PM
RE: syntax highlighting - by snippsat - Sep-15-2016, 08:41 PM
RE: syntax highlighting - by snippsat - Sep-16-2016, 06:58 PM
RE: syntax highlighting - by metulburr - Sep-16-2016, 08:05 PM
RE: syntax highlighting - by snippsat - Sep-16-2016, 08:44 PM
RE: syntax highlighting - by snippsat - Sep-16-2016, 10:52 PM
RE: syntax highlighting - by metulburr - Sep-16-2016, 11:31 PM
RE: syntax highlighting - by snippsat - Sep-17-2016, 07:17 PM
RE: syntax highlighting - by metulburr - Sep-17-2016, 08:24 PM
RE: syntax highlighting - by snippsat - Sep-18-2016, 01:37 AM
RE: syntax highlighting - by metulburr - Sep-18-2016, 02:01 AM
RE: syntax highlighting - by snippsat - Sep-18-2016, 11:44 AM
RE: syntax highlighting - by metulburr - Sep-18-2016, 01:24 PM
RE: syntax highlighting - by metulburr - Sep-18-2016, 01:26 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 04:17 AM
RE: syntax highlighting - by metulburr - Oct-04-2016, 04:30 AM
RE: syntax highlighting - by snippsat - Oct-04-2016, 05:25 AM
RE: syntax highlighting - by metulburr - Oct-04-2016, 05:28 AM
RE: syntax highlighting - by snippsat - Oct-04-2016, 05:36 AM
RE: syntax highlighting - by metulburr - Oct-04-2016, 05:46 AM
RE: syntax highlighting - by metulburr - Oct-04-2016, 05:48 AM
RE: syntax highlighting - by snippsat - Oct-04-2016, 12:53 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:14 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 01:32 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:27 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 01:49 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:41 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:44 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:53 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 01:59 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 02:03 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 02:08 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 02:11 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 02:26 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 02:39 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 02:41 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 02:56 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 03:01 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 03:10 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 03:18 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 03:25 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 03:27 PM
RE: syntax highlighting - by snippsat - Oct-04-2016, 06:04 PM
RE: syntax highlighting - by metulburr - Oct-04-2016, 06:14 PM
RE: syntax highlighting - by Larz60+ - Oct-05-2016, 03:18 AM
RE: syntax highlighting - by metulburr - Oct-05-2016, 03:52 AM
RE: syntax highlighting - by Larz60+ - Oct-05-2016, 05:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Undo (Ctrl+z) doesn't work on highlighting CynthiaMoore 8 8,408 Apr-25-2020, 05:00 AM
Last Post: buran
  feature request: highlighting Skaperen 9 6,530 Jan-26-2017, 04:13 PM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020