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
#2
[Image: shifty.gif]
.
.
.
.
AWESOME :o


edcept I don't like the pure white
why not the style like on the GeSHi website? and maybe a box telling what language it is =P and line numbers on the forums part. :wink:

Possible glitch:
[syntax="qbasic"]PRINt 3bob3[/syntax]

if number at begining at word it treats it as number (when in the program it should be an error so nvm =p )
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Quote:edcept I don't like the pure white
why not the style like on the GeSHi website? and maybe a box telling what language it is =P and line numbers on the forums part.

I made the style the same as a code box, but that can be changed.

The language thing is easy, I'll do that soon.

And I ditched the line numbers because I turned word wrap on. If word wrap is on, then line numbers get stuffed up on long lines, and if it's off you get people complaining that they have to scroll sideways, so I chose to have it on.

If anyone's got a suggestion for a colour scheme for the box that the source is in that will fit with all styles here I'm open to suggestions (though hopefully I will be able to make the styles change with a later version of this mod).
Reply
#4
Quote:I made the style the same as a code box, but that can be changed.

not for darksmart or whatever I'm using
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
Quote:Possible glitch:
[syntax="qbasic"]PRINt 3bob3[/syntax]

if number at begining at word it treats it as number (when in the program it should be an error so nvm =p )

Yea as you said, it would show an error, because that does not conform to the BASIC naming convention. Basic variables cannot start with a number Wink
Reply
#6
Cool, thanks Oracle! Big Grin
Reply
#7
Nice, except the white background looks like crap. It's really hard to see the light gray on it.
Reply
#8
^ So your colour suggestions are???

I'll fix the number problem tomorrow.
Reply
#9
...anything but light gray on white...I mean, are you trying to make us blind?

It looks ok in subSilver and SubOracle (because the text is black instead of light gray), but switch to smartDark and you'll see what I'm talking about.
Reply
#10
Uh oh! I just found a silly little bug. [syntax] still proccesses smilies.

[syntax="qbasic"]print "Hello Wink"
[/syntax]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)