Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generic Syntax Highlighting
#1
I've updated the generic syntax highlighter for QBnews. It's now up to 5,800% faster and doesn't use the database (downside below). But more importantly, it's better and it supports 6 languages: PHP, QuickBASIC (QBasic as well by extension), CSS, SQL, Java and C.

How do you use it? The same way as before: [syntax="language"] ... [/syntax], where at this time language is the one of the literal strings "php", "qbasic", "css", "sql", "java" or "c" (case insensitive). If you try to highlight a language that doesn't exist nothing will happen.

Here are a few demos:

[syntax="qbasic"]IF ( 1 = 2) THEN
PRINT "hello, world!"
END IF

FUNCTION foo (r%)
' comment with two spaces
' comment with no spaces
END FUNCTION

rem autocaps too: just quote this post to see

for i = 1 to 30 step 2
locate i, i mod 2
print "GeSHi!!!!!!!"
next i

do: loop until inkey$ <> ""
cls[/syntax]

A function in the phpBB template class:
[syntax="php"] /**
* Block-level variable assignment. Adds a new block iteration with the given
* variable assignments. Note that this should only be called once per block
* iteration.
*/
function assign_block_vars($blockname, $vararray)
{
if (strstr($blockname, '.'))
{
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.
$str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';

// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'][] = $vararray;
}
return true;
}[/syntax]

The top of subSilver.css

[syntax="css"]/*
The original subSilver Theme for phpBB version 2+
Created by subBlue design
http://www.subBlue.com
*/


/* General page style. The scroll bar colours only visible in IE5.5+ */
body {
background-color: #E5E5E5;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
}

/* General font families for common tags */
font,th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif }
a:link,a:active,a:visited { color : #006699; }
a:hover { text-decoration: underline; color : #DD6900; }
hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}


/* This is the border line & background colour round the entire page */
.bodyline { background-color: #FFFFFF; border: 1px #98AAB1 solid; }

/* This is the outline round the main forum tables */
.forumline { background-color: #FFFFFF; border: 2px #006699 solid; }


/* Main table cell colours and backgrounds */
td.row1 { background-color: #EFEFEF; }
td.row2 { background-color: #DEE3E7; }
td.row3 { background-color: #D1D7DC; }[/syntax]

More information can be found at the GeSHi website, including a demo form for you to explore the power of GeSHi (including uploading your own files, changing colours and styles etc).

I think this is a great improvement over the current version, and I urge you guys to use this when you can. I'm most greatful to all who do test this - your feedback will make GeSHi faster and better. And if you make a new language file for GeSHi (see the website) you'll get your name up in lights Smile

Have fun Big Grin
Reply


Messages In This Thread
Generic Syntax Highlighting - by oracle - 06-19-2004, 09:46 AM
Generic Syntax Highlighting - by oracle - 06-19-2004, 10:57 AM
Generic Syntax Highlighting - by whitetiger0990 - 06-19-2004, 11:05 AM
Generic Syntax Highlighting - by KiZ - 06-19-2004, 03:59 PM
Generic Syntax Highlighting - by TheBigBasicQ - 06-19-2004, 07:01 PM
Generic Syntax Highlighting - by Plasma - 06-20-2004, 12:45 AM
Generic Syntax Highlighting - by oracle - 06-21-2004, 01:38 AM
Generic Syntax Highlighting - by Plasma - 06-21-2004, 02:13 AM
Generic Syntax Highlighting - by KiZ - 06-21-2004, 05:28 PM
Generic Syntax Highlighting - by oracle - 06-22-2004, 02:31 AM
Generic Syntax Highlighting - by KiZ - 06-22-2004, 07:01 PM
Generic Syntax Highlighting - by oracle - 06-24-2004, 03:15 AM
Generic Syntax Highlighting - by oracle - 07-02-2004, 03:25 AM
Generic Syntax Highlighting - by Krule - 07-17-2004, 04:33 PM
Generic Syntax Highlighting - by oracle - 07-19-2004, 09:35 AM
Generic Syntax Highlighting - by Hard Rock - 07-20-2004, 07:02 PM
Generic Syntax Highlighting - by oracle - 07-21-2004, 06:38 AM
Generic Syntax Highlighting - by Sumo Jo - 07-21-2004, 10:41 AM
Generic Syntax Highlighting - by na_th_an - 07-21-2004, 05:09 PM
Generic Syntax Highlighting - by oracle - 07-22-2004, 06:45 AM
Generic Syntax Highlighting - by Diroga - 03-17-2005, 12:42 PM
Generic Syntax Highlighting - by TheBigBasicQ - 03-18-2005, 12:29 AM
Generic Syntax Highlighting - by adosorken - 03-18-2005, 12:33 AM
Generic Syntax Highlighting - by TheBigBasicQ - 03-18-2005, 12:37 AM
Generic Syntax Highlighting - by whitetiger0990 - 03-18-2005, 01:29 AM
Generic Syntax Highlighting - by Anonymous - 03-18-2005, 04:51 AM
Generic Syntax Highlighting - by Rattrapmax6 - 03-18-2005, 06:13 AM
Generic Syntax Highlighting - by diakin - 04-14-2005, 11:25 AM
Generic Syntax Highlighting - by KiZ - 04-14-2005, 03:01 PM
Generic Syntax Highlighting - by Anonymous - 04-14-2005, 03:04 PM
Generic Syntax Highlighting - by KiZ - 04-14-2005, 06:41 PM
Generic Syntax Highlighting - by ff - 07-21-2005, 11:45 PM
Generic Syntax Highlighting - by Sumo Jo - 07-22-2005, 04:46 AM
Generic Syntax Highlighting - by ff - 07-22-2005, 12:50 PM
Generic Syntax Highlighting - by whitetiger0990 - 06-19-2004, 10:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)