Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Syntax Highlighter (beta)
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #1
Syntax Highlighter (beta)
This is my first ever attempt at writing a syntax highlighter.  I have not looked into anyone else's code either, so I'm proud to say that I thought up all the algorithms used in this code by myself (though someone else may have already used them, IDK >_>).

Doing a few benchmarks against GeSHi (what's used on most forum systems, like phpBB and vBulletin), my code performs, on average, 2 times faster.  XML/HTML is done by a dedicated algorithm, so is usually around 5-6 times faster than GeSHi.
Still, it's rather slow, plus, my algorithm has a little flaw, which, in a worst case scenario, may cause it to run quite slowly.  For most codes however, it shouldn't be an issue.
I suggest installing a preparser if you plan on using this.

One thing to note is that this algorithm is more designed for speed
than ease of extensibility, unlike GeSHi.

Features:
  • Tabs are displayed correctly (not converted to spaces)
  • Adds a Select button for easy code selection
  • Supported languages:
    • C
    • C++
    • Java
    • Visual Basic
    • PHP (custom)
    • XML/HTML
    • Javascript
    • Assembler
    • SQL
    • Batch
    • INI

Note that this plugin requires two code edits to /inc/class_parser.php.  Details on the code edits are provided in the package, as well as a pre-edited MyBB 1.2.10-1.2.12 file.

.rar  syntaxh.rar (Size: 19.59 KB / Downloads: 1321)
(keyword lists were copied from Notepad++ - I didn't write them up myself; props to the authors of Notepad++ for that, and also, for the awesome editor)
EDIT: Updated


Demonstrations

C Code
1
2
3
4
5
6
#include <stdio.h>
int main()
{
	printf("Goodbye, cruel world... :(");
	return 0;
}

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$myvar = 'b';
?>
<html>
<head>
<script language="javascript">
<!--
function runstuff()
{
	var mytext = "hullo";
	if(mytext.match(/hu?llo/i))
		alert("Hey!");
}
//-->
</script>
</head>
<body onload="runstuff();">
<?php
echo "This is variable \$myvar: $myvar";
?>
<img src="http://someplace" />
</body></html>

Batch Script
if exist %1 goto end
for %%a IN *.exe DO echo "%%a"
:end


SQL Code
SELECT * FROM mybb_users WHERE username LIKE "%me%"


My Blog
(This post was last modified: 01-29-2008 09:33 PM by ZiNgA BuRgA.)
01-26-2008 01:23 AM
Find all posts by this user
pepotiger Offline
Junior Member
**
Posts: 18
Joined: Jan 2008
Post: #2
RE: Syntax Highlighter (beta)
hey mate. you just starting helping your forum to grow up.
I would like to be a part of this action.
and thanks for this great plugin gonna try it
01-26-2008 08:10 AM
Find all posts by this user
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #3
RE: Syntax Highlighter (beta)
Thanks pepotiger for that!

My Blog
01-26-2008 10:48 AM
Find all posts by this user
blueparukia Offline
Junior Member
**
Posts: 35
Joined: Jan 2008
Post: #4
RE: Syntax Highlighter (beta)
This is incredible, exactly what I've wanted in MyBB for a long while now (second only to the Mod CP I think). I could never get Geshi to work, and the lovely select all button is great. You'd better update this for 1.4 Tongue
01-27-2008 07:57 PM
Find all posts by this user
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #5
RE: Syntax Highlighter (beta)
Lol, thanks blueparukia.  ModCP is coming in 1.4 so you shouldn't need to worry Smile

This was more of a personal challenge.  It was interesting rewriting the algorithm about 5 times to get it to go this fast.


I didn't find getting GeSHi to work too difficult.  In fact, I may make an integration plugin for it, for those who want the extra languages, or just like it better Tongue

My Blog
(This post was last modified: 01-27-2008 11:07 PM by ZiNgA BuRgA.)
01-27-2008 11:06 PM
Find all posts by this user
MrDoom Offline
Junior Member
**
Posts: 2
Joined: Jan 2008
Post: #6
RE: Syntax Highlighter (beta)
Looks really good, the PHP highlighting seems very NotePad++ like Tongue
01-28-2008 12:56 AM
Find all posts by this user
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #7
RE: Syntax Highlighter (beta)
Thanks MrDoom Smile
Hehe, I use Notepad++ to edit all my files, so I guess I'm influenced by it.
But one can easily edit the CSS file to suit oneself: http://mybbhacks.zingaburga.com/css/highlight.css

My Blog
01-28-2008 06:42 PM
Find all posts by this user
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Syntax Highlighter (beta)
Found a little minor security exploit with this.
Have updated the package to patch it.

My Blog
01-29-2008 09:35 PM
Find all posts by this user
terra_c Offline
Junior Member
**
Posts: 2
Joined: Feb 2008
Post: #9
RE: Syntax Highlighter (beta)
Hi!

Nice work, ZiNgA BuRgA (my english is bad, sorry - i come from germany Wink)!
I have installed your Plugin and i find that great, but i need line numbers for this Plugin. You can make this?

Thanks
02-07-2008 10:40 AM
Find all posts by this user
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #10
RE: Syntax Highlighter (beta)
Hi terra_c,

Actually, I originally had line numbers, however, there's an odd alignment issue with Firefox I can't seem to fix.  For some reason, the line numbers wouldn't line up with the actual lines in Firefox... Ouch

It's not too difficult if you want to do it yourself, but I can't help you on misalignment.

My Blog
02-07-2008 01:19 PM
Find all posts by this user

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: