|
-
Nov 7th, 2003, 11:43 AM
#1
Thread Starter
Member
vb code syntax highlighting?
this is baking my noodle!
here and on code guru, i think they use the same boards, because when one is down, so is the other.. so here i was hoping to find the answer to:
what is the vb tag to make code syntax highlighted?
Code:
merely puts things in black
[vb] doesnt work (ala [/vb]
[visualbasic]
if then else 'guess
[/visualbasic]
[visual basic]
if then else 'guess
[/visual basic]
[vb code]
if then else 'guess
[/vb code]
[code language=vb]
if then else 'guess
[/code]
-
Nov 7th, 2003, 11:46 AM
#2
Thread Starter
Member
ahhh
vbcode.
that doesnt work on codeguru forums, so how do people there get it highlighted?
-
Nov 7th, 2003, 11:46 AM
#3
VB Code:
'this seems to work for me
If youuse=[ vbcode ] - spaces Then
Success=True
End If
-
Nov 7th, 2003, 12:02 PM
#4
-
Nov 7th, 2003, 12:15 PM
#5
I can't speak for how to do it on CodeGuru, but here it is [vbcode][/vbcode] or the new VB button, and yes, it's case sensitive, but then again if you think about it so is VB. VB however will capitalize things for you when necessary and I don't think you can expect simple tags to have that functionality.
-
Nov 7th, 2003, 02:06 PM
#6
Stuck in the 80s
Originally posted by MartinLiss
and I don't think you can expect simple tags to have that functionality.
Oh yes you can! 
If I could see how the vbcode tag works, I could probably tweak it to automatically capitalize words. I'm sure it just uses a preg_replace() or something in PHP, so it would quite easy to make it capitalize them.
-
Nov 7th, 2003, 02:08 PM
#7
But you wouldn't want it to capitalize all words, just the ones that VB would capitalize.
-
Nov 7th, 2003, 02:16 PM
#8
Stuck in the 80s
Exactly. If it's a regular expression, and there's an array of key words to colorize, you could loop the array, colorizing each keyword, and replacing the original word with the properly cased keyword from the array.
Sorry if that's confusing. Using a loop might slow it down a bit, so I'd have to test it to be sure...and I know you guys don't like modifying the board code because of updates and having to redo it...but I'm just saying...it's possible, and quite easy.
That's all.
-
Nov 7th, 2003, 02:28 PM
#9
How would you obtain the the array of key words? Once you had them and you made sure that they were capitalized you wouldn't have to do any additional colorizing.
-
Nov 7th, 2003, 02:42 PM
#10
Stuck in the 80s
I'm not sure I know what you're talking about, Martin?
I figured there would be an array of keywords in the php code that it's using to search the post text and then colorize accordingly, probably using regular expressions and the preg_replace() function in PHP.
-
Nov 7th, 2003, 02:45 PM
#11
Oh, you're right, I didn't think about the fact that there already has to be a array.
-
Nov 7th, 2003, 02:57 PM
#12
Stuck in the 80s
This is just assuming that vBulletin does it this way.
Code:
<?php
// Setup keyword array:
$keywords = array('If', 'End If', 'Then', 'End', 'Dim', 'As', 'Integer', 'String', 'Function', 'Sub');
// Setup example text:
$post_text = 'dim x as integer
if x > 10 then
Text1.Text = "Number is too large!"
end if';
// Format the array:
array_walk($keywords, 'formatItem');
// Colorize the keywords:
$formatted_text1 = preg_replace($keywords, '<span style="color: #0000a0;">\\1</span>', $post_text);
// Ouput the text:
echo '<hr /><pre>' . nl2br($formatted_text1) . '</pre><hr />';
// NEW CAPITALIZATION METHOD:
// Setup the array:
$keywords = array('If', 'End If', 'Then', 'End', 'Dim', 'As', 'Integer', 'String', 'Function', 'Sub');
// Loop the example text, colorize and replace keywords:
$formatted_text2 = $post_text;
for ($i = 0; $i < count($keywords); $i++) {
$formatted_text2 = preg_replace('/(' . $keywords[$i] . ')/i',
'<span style="color: #0000a0;">' . $keywords[$i] . '</span>', $formatted_text2);
}
// Ouput the text:
echo '<hr /><pre>' . nl2br($formatted_text2) . '</pre><hr />';
// Function used in first example:
function formatItem(&$item, $key) {
$item = "/($item)/i";
}
?>
I know that's probably all gibberish to anyone who doesn't know PHP, but you can see the output here (ignore the double-spacing problem).
-
Nov 7th, 2003, 02:59 PM
#13
Stuck in the 80s
Now that I think of it, maybe vBulletin just doesn't colorize based on case insensitivity. If that's the case, it'd be easy to make it colorize the lowercase words, but they would then stay lowercase.
Again, I'm not sure since I don't know how vBulletin does it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|