Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 syntax highlighting
#1
There is a plugin installed that allows syntax highlighting. The BBCode for it is
[shcode=python]CODE HERE[/shcode]
EDIT:
The BBCode button for it looks like [], in the reply editor


Python
[shcode=python]
class Ship:
    def __init__(self, sheet):
        self.frames = strip_from_sheet(sheet, (0,0), (122,164), 4, 4)
        self.frame_index = 0
        self.update()
        
    def update(self):
        self.image = self.frames[self.frame_index]
        
    def get_event(self, event):
        if event.type == pg.KEYDOWN:
            self.frame_index += 1
        
    def draw(self, screen):
        screen.blit(self.image, (0,0))
[/shcode]

XML
[shcode=xml]
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>
[/shcode]

Regular code box
class Ship:
    def __init__(self, sheet):
        self.frames = strip_from_sheet(sheet, (0,0), (122,164), 4, 4)
Supported Languages :
ActionScript3 : as3
Bash/shell : bash
ColdFusion : cf
C# : c-sharp
C++ : cpp
CSS : css
Delphi : delphi
Diff : diff
Erlang : erlang
Groovy : groovy
JavaScript : jscript
Java : java
JavaFX : javafx
Perl : perl
PHP : php
Plain Text : plain
PowerShell : ps
Python : python
Ruby : rails
SQL : sql
Scala : scala
Visual Basic : vbnet
XML : xml
Quote
#2
Testing out shcode,it's ok first code i paste.
If i try to past in the same code one more time the original code block activates and make some html?
I get some times some strange errors in last line of some code.

[shcode=python]from collections import deque
from itertools import islice

def window(iterable, size=2):
   iterable = iter(iterable)
   d = deque(islice(iterable, size), size)
   yield d
   for x in iterable:
       d.append(x)
       yield d[/shcode]

Here is [_shcode=python]
[shcode=python]
from collections import deque
from itertools import islice

def window(iterable, size=2):
    iterable = iter(iterable)
    d = deque(islice(iterable, size), size)
    yield d
    for x in iterable:
        d.append(x)
        yield d
[/shcode]

Here is [_shcode=python]
[shcode=python]
with open('numb.txt') as f_obj:
    number = int(f_obj.read())
    if number > 10000:
        number = number - 100
        print(number)
    else:
        print(number)
[/shcode]


Here i just paste in code,and code block auto hit in.
with open('numb.txt') as f_obj:
    number = int(f_obj.read())
    if number > 10000:
        number = number - 100
        print(number)
    else:
        print(number)
Quote
#3
It looks like the last two have nested code tags while the first does not. shcode is its own tag and does not need regular code tags. The regular code tags seem to be escaping the syntax highlighter html. If i copy the same tag over and over i just get the expected outcome of new syntax code boxes. Can you give a description on what exactly you are doing? Oh and i got a button up and running for shcode, it should be the one next to quotes that is just two brackets []. 

[shcode=python]from collections import deque
from itertools import islice

def window(iterable, size=2):
   iterable = iter(iterable)
   d = deque(islice(iterable, size), size)
   yield d
   for x in iterable:
       d.append(x)
       yield d[/shcode]

[shcode=python]from collections import deque
from itertools import islice

def window(iterable, size=2):
    iterable = iter(iterable)
    d = deque(islice(iterable, size), size)
    yield d
    for x in iterable:
        d.append(x)
        yield d[/shcode]

[shcode=python]with open('numb.txt') as f_obj:
    number = int(f_obj.read())
    if number > 10000:
        number = number - 100
        print(number)
    else:
        print(number)[/shcode]
Quote
#4
Quote:Can you give a description on what exactly you are doing?

I have figure out the problem,try copy some code from a website eg here or here
It will not clean up the html,have to first copy into a editor then into code box.
Quote
#5
oh i see. Yes i am getting that also.

Ill check up on that.
Quote
#6
There's a problem with the shcode:

[shcode=python]
user = 'ichabod801'
[/shcode]

See how it's backslashing all the single quotes? I did\'t put those in there. That code wouldn't run in the interpreter.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#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;
}
?>
Quote
#8
Quote:There's a problem with the shcode:
I had look into this,tried some regex changes but soon figured out that problem was not there.
There is a bug in parser shCore.js,this error has never been fixed.
So have to try what's in the post,problem is that shCore.js is a compressed version.
I did applied changes to shCore.js uncompressed and will not run.
Think i need XRegExp.js  in same folder to run a uncompressed version of shCore.js .

So not so easy,will try a little more :dodgy:
Much of this is older stuff that has not been fixed.
MyBB 2.0 Markdown :cool:
Quote
#9
the mybb plugin is a wrapper around
https://github.com/syntaxhighlighter/syntaxhighlighter

But the plugin itself is older...and appears to be not as updated as the github repo. Im wondering if we might be running an older version that does not have these issues fixed. 

maybe if we compare and contrast the plugin code between the latest github code, these issues might of been resolved.
Quote
#10
based on this issue
https://github.com/syntaxhighlighter/syn...issues/366

it looks like the devs expect you to escape the HTML
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  feature request: highlighting Skaperen 9 2,199 Jan-26-2017, 04:13 PM
Last Post: Kebap

Forum Jump:


Users browsing this thread: 1 Guest(s)