PDA

View Full Version : BB Code Enhancements - Better code syntax highlighting


Sarteck
07-24-2012, 10:00 PM
This Modification is meant more as an example than an actual modification, but will work fine as is.

vBulletin by default has three "code" BB Codes.

The [CODE] tag simply gives us monospaced text.

The [HTML] and [PHP] tags give us some highlighted code that's highlighted pretty much how our webserver software decides how to highlight it. For "serious" coding, that's often insufficient.

GeSHi (http://qbnz.com/highlighter/index.php) provides much more accurate highlighting and in a vast number of different languages. It's relatively simple to add these languages to your own BB Codes for highlighting, too.

Attached is the latest version of the GeSHi files, 1.0.8.10. You may go to their website at any time and download newer releases, though the latest was released well over a year ago. (I had to repackage it as a ZIP file, because vB.org doesn't accept tar.gz files.)

Download and extract this file. Upload the geshi.php file and the geshi folder to your FORUMROOT/includes folder.

Download the XML product file and Import it as you would a regular Product through your Admin Control Panel. It will install a plugin that contains BB Code functions for the following languages:


PHP (as [PHPS])
JavaScript (as [JSS])
CSS (as [CSSS])
SQL (as [SQLS])
C++ (as [CPPS])
HTML (as [HTMLS])
Java (as [JAVAS])
Tcl (as [TCLS])
BASH (as )
(If you're wondering, the "S" stands for "Source".)

By looking through those examples, you can see how to easily add other languages GeSHi handles as well (Lua for some of you game programmers, for example).



This has really helped me communicate code stuff withmy Admins for our forum a lot better than the default vBulletin stuff, and it's nice to have for the coders at my forum as well.



Updated (25.JUL.12) [0.02a]
Included install and uninstall scripts that INSERT or DELETE the above BB Codes to/from your database. [B]WARNING! If you have a BB Code named the same as one of the above that you do NOT want deleted, this product will delete that BB Code from the database if you use the Uninstall script. Just wanted to make that clear.

Updated (01.AUG.12) [0.03a]
Product was previously Disabled by default AND (even after enabling product) the Plugin was disabled. Both are now enabled by default.

Updated (01.AUG.12) [0.04a]
Fixed an error from 0.03a that gave SQL errors when trying to update the product. >_>

Sarteck
07-25-2012, 09:21 AM
I'd also request that the Staff here consider using GeSHi for making stuff all prettified. X3 It's obviously not a necessity, but it'd be nice to have code highlighting for SQL, CSS, and JavaScript at least.

Sarteck
07-25-2012, 11:06 AM
Updated to include Install/Uninstall scripts that will add (or delete) the BB Codes automatically for you. Now all you need to do is upload the files and import the XML.

ryohnosuke
08-01-2012, 06:46 AM
it's working? I'm only getting:

{PlaceHolder}

Saludos.

Sarteck
08-01-2012, 09:05 AM
The product was previously disabled by default, and even after enabling the Product, the Plugin was disabled by default.

Both are now enabled by default in v0.03a, so you can download and over-write to fix, or you can simply enable both the Product and then Plugin.

My bad, oops. ^^;

ryohnosuke
08-01-2012, 03:50 PM
I uninstalled it and when I want to install your fixed version:

Database error in vBulletin 4.2.0:

Invalid SQL:
INSERT INTO `vB_bbcode` (`bbcodetag`, `bbcodereplacement`, `bbcodeexample`, `bbcodeexplanation`, `twoparams`, `title`, `buttonimage`, `options`) VALUES
('PHPS', '{Place Holder}', '/** Sample **/ echo "Hello Shitty World";', 'HIghlights PHP with the Geshi highlighter.', 0, 'PHP v2', '', 1),
('JSS', '{Place Holder}', 'alert(''blah''+"\\n"+bleh);', 'JavaScript Syntax Highlight', 0, 'JavaScript Source', '', 1),
('CSSS', '{Place Holder}', '.thisclass {font-size:13px;}', 'CSS Source Syntax Highlighting', 0, 'CSS Source', '', 1),
('CPPS', '{Place Holder}', 'cout << "Enter number: ";', 'Highlights C++ with the Geshi highlighter.', 0, 'C++ Source', '', 1),
('HTMLS', '{Placeholder}', '<html><head><title>Bleh</title></head><body>Blah</body></html>', 'Highlights HTML Source with the GeSHi Highlighter.', 0, 'HTML Source', '', 1),
('JAVAS', '{PlaceHolder}', '/*JavaCode*/', 'Highlights Java with the GeSHi highlighter.', 0, 'Java Source', '', 1),
('SQLS', '{PlaceHolder}', 'insert into mytable (field1,field2) VALUES (1,4);', 'Highlights MySQL with the GeSHi highlighter.', 0, 'MySQL Source', '', 1),
('TCLS', '{PlaceHolder}', 'set token [http::geturl "http://www.clubbleach.org/forums/bwbots.php" -query $querystring]', 'Highlights Tcl with the GeSHi highlighter.', 0, 'Tcl Source', '', 1),
('BASHS', '{PlaceHolder}', 'woogypid=`ps $(cat /usr/lib/eggdrop/pid.Woogy) | grep $(cat /usr/lib/eggdrop/pid.Woogy) 2> /dev/null | awk ''{print $1}''`', 'For BASH environment syntax highlighting.', 0, 'BASH code', '', 1);;

MySQL Error : Duplicate entry 'PHPS-0' for key 'uniquetag'
Error Number : 1062
Request Date : Wednesday, August 1st 2012 @ 11:48:40 AM
Error Date : Wednesday, August 1st 2012 @ 11:48:40 AM
Script : http://www.ryohnosuke.com/foros/admincp/plugin.php?do=productimport
Referrer : http://www.ryohnosuke.com/foros/admincp/plugin.php?do=productadd
IP Address : *********
Username : ********
Classname : vB_Database_MySQLi
MySQL Version : 5.1.63-cll

Sarteck
08-01-2012, 07:48 PM
Sorry, man. My bad for including install code where not necessary. (Thought I needed one for each version, apparently I only need it for the earliest version.)

Everything fixed in 0.04a.

Or... hopefully. XD That's what the "a" is there for, after all.

Sarteck
08-01-2012, 07:49 PM
Also, En Taro Adun.

ryohnosuke
08-01-2012, 08:02 PM
Ok it works! : D, how can I set up the number lines?

Saludos.

Sarteck
08-02-2012, 02:07 AM
There's a line,

//$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);// (Disabled Line Numbers)

Uncomment that.

tcarr9
08-02-2012, 12:38 PM
Thanks so much - installed and working nicely. I even modified it to include an AS3S tag for ActionScript3 since that is used on my forums frequently.

Sarteck
08-02-2012, 12:47 PM
You're welcome, but thank the GeSHi coders more than me. :P All I did was show how to use it for vBulletin--they're the ones who provided such an awesome project. :3

SolidSnakeLive
08-06-2012, 06:58 PM
How to add button for lua ?

I added a lines in XML file for lua

But the button didn't show up in Editor ... I have already put a pic for it !

Can you tell me how to add a button in editor or make this mod with buttons ?

Sarteck
08-07-2012, 02:16 AM
On the plugin GeSHi BB Codes (hook location bbcode_create), add the following:




/// LUAS
$this->tag_list['no_option']['luas'] = array ();
$this->tag_list['no_option']['luas']['callback'] = 'handle_external';
$this->tag_list['no_option']['luas']['external_callback'] = 'handle_geshi_lua';
if (!function_exists ('handle_geshi_lua'))
{
function handle_geshi_lua(&$theobj, &$value, &$option)
{
$code = handle_geshi_code($value,'lua');
return '<div class="bbcode_container"><div class="bbcode_description">Lua Code:</div><div style="max-height: 300px;" class="bbcode_code">'.$code.'</div></div>';
}
}

In the Admin Control Panel, Custom BB Codes ---> Add New BB Code.
Title: Lua Source Code
BB Code Tag Name: luas
Replacement: {Placeholder}
Example: print("Herro World")
Description: Prints out Lua code all nicely formatted.
Use {option}: No
Button Image (Optional): --here is where you would specify a button image.
Remove Tag If Empty: Yes
Disable BB Code Within This BB Code: Yes (well, depends on if you want or not)
Disable Smilies Within This BB Code: Yes
Disable Word Wrapping Within This BB Code: No
Disable Automatic Link Parsing Within This BB Code: Yes

Then test it out.

SolidSnakeLive
08-07-2012, 04:14 AM
On the plugin GeSHi BB Codes (hook location bbcode_create), add the following:




/// LUAS
$this->tag_list['no_option']['luas'] = array ();
$this->tag_list['no_option']['luas']['callback'] = 'handle_external';
$this->tag_list['no_option']['luas']['external_callback'] = 'handle_geshi_lua';
if (!function_exists ('handle_geshi_lua'))
{
function handle_geshi_lua(&$theobj, &$value, &$option)
{
$code = handle_geshi_code($value,'lua');
return '<div class="bbcode_container"><div class="bbcode_description">Lua Code:</div><div style="max-height: 300px;" class="bbcode_code">'.$code.'</div></div>';
}
}

In the Admin Control Panel, Custom BB Codes ---> Add New BB Code.
Title: Lua Source Code
BB Code Tag Name: luas
Replacement: {Placeholder}
Example: print("Herro World")
Description: Prints out Lua code all nicely formatted.
Use {option}: No
Button Image (Optional): --here is where you would specify a button image.
Remove Tag If Empty: Yes
Disable BB Code Within This BB Code: Yes (well, depends on if you want or not)
Disable Smilies Within This BB Code: Yes
Disable Word Wrapping Within This BB Code: No
Disable Automatic Link Parsing Within This BB Code: Yes

Then test it out.

Well thanks for reply

But this did not work ...

There is no LUA button in editor

I did what you say exactly :(

SolidSnakeLive
08-07-2012, 04:52 AM
Its works the problem is I was using a plugin that add more buttons to editor such as pdf / flash / advanced colors ...etc

when i disabled it .... it works !

I don't know if there a solution to keep both works :confused:

Sarteck
08-07-2012, 10:44 AM
Hmm. What's the modification? Can you link it? Maybe I can modify my thing to be compatible with it (although I'm not sure why it would be incompatible).

SolidSnakeLive
08-22-2012, 03:35 AM
Hmm. What's the modification? Can you link it? Maybe I can modify my thing to be compatible with it (although I'm not sure why it would be incompatible).

Its Editor tool addon

This Product :

http://www.wahtaljouf.com/wahtools/wah-tools-editor.zip

same but UTF-8 Encoding : http://www.wahtaljouf.com/wahtools/wah-tools-editor-utf8.zip

Info : http://www.traidnt.net/vb/traidnt1998010/
Its in Arabic language not English but you can see the images to have the idea about this product

SpikedRocker
09-12-2012, 11:57 AM
When I've tried using this mod, at least with the php code, it actually was causing an error when you try to load the thread. Has anyone else experienced this?

SolidSnakeLive
09-13-2012, 08:47 AM
Can you make this script looks like this codebox

http://forum.mtasa.com/viewtopic.php?f=91&t=47798#p473505

appears as code with using lua highlight support & ofcource with rows id

SpikedRocker
09-16-2012, 02:56 PM
The product was previously disabled by default, and even after enabling the Product, the Plugin was disabled by default.

Both are now enabled by default in v0.03a, so you can download and over-write to fix, or you can simply enable both the Product and then Plugin.

My bad, oops. ^^;

I have this issue using .04

Anyone know how to fix this?

TheSupportForum
10-07-2012, 11:56 PM
this does nto work for 4.2.0

each time an post is edited the BBCode is removed

khronos_group
10-10-2012, 02:15 PM
I've successfully installed your product and have successfully added GLSL! Yay! Thank you.

I have one issue though: We use the fancy editor in vBulletin, and once we add the tags--for any code block-- and preview or save the post, the tags are removed and the code is saved as converted already into its fancy format. If we come back to edit the code, and save, our code is all smushed up onto one line.

Is there a way to have the tags remain in our posts and not get converted, much like how the normal BB Code tags work?

Thank you.

Screen shot of issue for clarity https://skitch.com/outofcontrol/eaxw1/official-feedback-on-opengl-4.3-thread-reply-to-topic

Cadellin
10-18-2012, 08:33 AM
each time an post is edited the BBCode is removed

Similar issue here. When editing the BBcode is removed and replaced with HTML which isn't repostable.

Widey
02-17-2013, 02:51 PM
Did anybody get this working in 4.2 in the end or is it still removing the BBCode when a post is edited?

karel1985
04-29-2013, 05:32 PM
is this working on 4.2.1 ?

conchemimare
06-04-2013, 07:42 PM
I got it to work on vb 4.2.1

No problems so far.

Madej
08-26-2013, 03:38 AM
And anyone know how to hide the contents of the code in the post for guest?

Raptor
11-18-2013, 06:02 PM
Did anybody get this working in 4.2 in the end or is it still removing the BBCode when a post is edited?


It still removes the codebox when the post is edited

until thats fixed its pretty useless for me unfortunatley

Raptor
11-18-2013, 06:02 PM
Can you make this script looks like this codebox

http://forum.mtasa.com/viewtopic.php?f=91&t=47798#p473505

appears as code with using lua highlight support & ofcource with rows id

i'd love this - cant find the mod anywhere though

aminp30
06-03-2014, 02:41 AM
it seems geshi support vb codes. but there is no vb tag after installation.
is there any way to solve it?

aminp30
07-22-2014, 07:45 AM
this does nto work for 4.2.0

each time an post is edited the BBCode is removed

Similar issue here. When editing the BBcode is removed and replaced with HTML which isn't repostable.

Did anybody get this working in 4.2 in the end or is it still removing the BBCode when a post is edited?

I have this problem too.
is there any solution? :confused:

thetechgenius
09-16-2014, 04:55 PM
Is there anyway to add these to a single BB Code? I would like to add all of them to the "Code" BB Code, and have them automatically detect and highlight the correct Code Syntax. I think it will be easier for members, then using Multiple Code BB Codes for different Code Languages.

tbworld
09-16-2014, 05:39 PM
Language highlighting is typically determined by the extension used on the file name. Since there is no file name extension given in a vbulletin code box the individual BBCODES are probably necessary. Note - I have not looked at the code to this modification. :)

errorware
11-10-2014, 10:00 PM
Any chance to change the colors for a dark theme? Is that to much of a hassle?

Cheers

john7911
11-15-2014, 01:14 PM
Need to have BB code for AutoLISP
http://en.wikipedia.org/wiki/AutoLISP
Thank you.

derbi
12-02-2014, 07:53 AM
There are a demo?

ozzy47
12-02-2014, 09:22 AM
Not that I have seen, best way to demo something is to install it and test it out. :)

Wedframe
07-08-2015, 10:59 AM
Hi. Maybe for somebody its steel actual.
To correct the problem with disappearing content after editing the message , it is necessary in the module GeSHi BB Codes, at hook bbcode_create to add the following code:
if ($this->is_wysiwyg())
{
$this->unparsed_tags[] = 'phps';
$this->unparsed_tags[] = 'jss';
$this->unparsed_tags[] = 'htmls';
$this->unparsed_tags[] = 'mysqls';
$this->unparsed_tags[] = 'ahks';
$this->unparsed_tags[] = 'au3s';
$this->unparsed_tags[] = 'avss';
$this->unparsed_tags[] = 'diffs';
$this->unparsed_tags[] = 'xmls';
$this->unparsed_tags[] = 'bashs';
//....and so do this, for all used bbcodes...
}
Hope this will be useful... :)

Raptor
07-18-2015, 11:46 PM
Hi. Maybe for somebody its steel actual.
To correct the problem with disappearing content after editing the message , it is necessary in the module GeSHi BB Codes, at hook bbcode_create to add the following code:
if ($this->is_wysiwyg())
{
$this->unparsed_tags[] = 'phps';
$this->unparsed_tags[] = 'jss';
$this->unparsed_tags[] = 'htmls';
$this->unparsed_tags[] = 'mysqls';
$this->unparsed_tags[] = 'ahks';
$this->unparsed_tags[] = 'au3s';
$this->unparsed_tags[] = 'avss';
$this->unparsed_tags[] = 'diffs';
$this->unparsed_tags[] = 'xmls';
$this->unparsed_tags[] = 'bashs';
//....and so do this, for all used bbcodes...
}
Hope this will be useful... :)

perfect! thank you very much :)

works in vb 4.2.3

Raptor
07-19-2015, 12:09 AM
Here is the changes to add 'Select All' to this mod (thanks to BCP Hung for his select all mod which I used for this (https://vborg.vbsupport.ru/showthread.php?t=264981)) and also fixed the edit issue so that you can edit the code without everything parsing with no problems (thanks to wedframe in the previous post) :)

Insert javascript code into headinclude template
AdminCP -> Styles & Templates -> Style Manager -> Edit Templates -> headinclude
Copy and paste following js code to bottom of headinclude template :


<script type="text/javascript">
function selectAll(a)
{
var e = a.parentNode.parentNode.getElementsByTagName('code ')[0];
if (window.getSelection)
{
var s = window.getSelection();
if (s.setBaseAndExtent)
{
s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
}
else
{
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
else if (document.getSelection)
{
var s = document.getSelection();
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
else if (document.selection)
{
var r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
</script>


then import and overwrite the new xml - enjoy :)

Tested on vb 4.2.3

Here's info to add the custom bbcode buttons to Quick Reply and Quick Edit

https://vborg.vbsupport.ru/showpost.php?p=2388624&postcount=15

GHRake
05-30-2017, 10:26 PM
anyone had trouble with highlight bbcode doing this in the code blocks:
https://vborg.vbsupport.ru/external/2017/05/19.png

I'm at a loss here :(

RaYdeN.ADM
08-16-2017, 06:01 AM
<font color="DeepSkyBlue">This plugin ruined the forum, do you know any way to restore bbcode php html default, after deleting the plugin?</font>

RaYdeN.ADM
08-20-2017, 10:19 PM
Any idea?

Raptor
07-28-2021, 02:01 PM
I have a weird one. Used this plugin for a few years now and works great. However I've come across some code that simply will not parse no matter what. Can anyone assist?

This is the code when parsed with standard CODE wrappers.


*/ picture
const int16 BOOT_LOGO[] = {
128, 49,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0FFF,0xFFFF,0xE007,0xFFFF,0xFFFE,0x007C,0x0000,0 x0078,0x1FFF,0xFFFF,0xF00F,0xFFFF,0xFFFF,
0x00FE,0x0000,0x00FC,0x1FFF,0xFFFF,0xF80F,0xFFFF,0 xFFFF,0x00FF,0x0000,0x00FC,0x1FFF,0xFFFF,
0xF007,0xFFFF,0xFFFF,0x00FF,0x8000,0x00FC,
0x0FFF,0xFFFF,0xE003,0xFFFF,0xFFFE,0x00FF,0xC000,0 x00FC,0x0000,0x000F,0xE000,0x0000,0x0000,
0x00FF,0xE000,0x00FC,0x0000,0x001F,0xC000,0x0000,0 x0000,0x00FF,0xE000,0x00FC,0x0000,0x003F,
0x8000,0x0000,0x0000,0x00FF,0xF000,0x00FC,
0x0000,0x007F,0x0000,0x0000,0x0000,0x00FF,0xF800,0 x00FC,0x0000,0x00FE,0x0000,0x0000,0x0000,
0x00FD,0xFC00,0x00FC,0x0000,0x01FC,0x0000,0x0000,0 x0000,0x00FC,0xFE00,0x00FC,0x0000,0x03F8,
0x0000,0x0000,0x0000,0x00FC,0x7F00,0x00FC,
0x0000,0x07F0,0x0000,0x0000,0x0000,0x00FC,0x3F80,0 x00FC,0x0000,0x07F0,0x0000,0x0000,0x0000,
0x00FC,0x1FC0,0x00FC,0x0000,0x0FE0,0x0000,0x0000,0 x0000,0x00FC,0x1FE0,0x00FC,0x0000,0x1FC0,
0x0000,0x0000,0x0000,0x00FC,0x0FF0,0x00FC,
0x0000,0x3F80,0x0007,0xFFFF,0xFFFE,0x00FC,0x07F0,0 x00FC,0x0000,0x7F00,0x000F,0xFFFF,0xFFFF,
0x00FC,0x03F8,0x00FC,0x0000,0xFE00,0x000F,0xFFFF,0 xFFFF,0x00FC,0x01FC,0x00FC,0x0001,0xFC00,
0x0007,0xFFFF,0xFFFE,0x00FC,0x00FE,0x00FC,
0x0003,0xF800,0x0003,0xFFFF,0xFFFC,0x00FC,0x007F,0 x00FC,0x0003,0xF800,0x0000,0x0000,0x0000,
0x00FC,0x003F,0x80FC,0x0007,0xF000,0x0000,0x0000,0 x0000,0x00FC,0x001F,0xC0FC,0x000F,0xE000,
0x0000,0x0000,0x0000,0x00FC,0x000F,0xE0FC,
0x001F,0xC000,0x0000,0x0000,0x0000,0x00FC,0x000F,0 xF0FC,0x003F,0x8000,0x0000,0x0000,0x0000,
0x00FC,0x0007,0xF0FC,0x007F,0x0000,0x0000,0x0000,0 x0000,0x00FC,0x0003,0xF8FC,0x00FE,0x0000,
0x0000,0x0000,0x0000,0x00FC,0x0001,0xFCFC,
0x01FC,0x0000,0x0000,0x0000,0x0000,0x00FC,0x0000,0 xFEFC,0x03F8,0x0000,0x0000,0x0000,0x0000,
0x00FC,0x0000,0x7FFC,0x03F8,0x0000,0x0000,0x0000,0 x0000,0x00FC,0x0000,0x3FFC,0x07F0,0x0000,
0x0000,0x0000,0x0000,0x00FC,0x0000,0x1FFC,
0x0FE0,0x0000,0x0000,0x0000,0x0000,0x00FC,0x0000,0 x0FFC,0x1FFF,0xFFFF,0xE003,0xFFFF,0xFFFC,
0x00FC,0x0000,0x07FC,0x3FFF,0xFFFF,0xF007,0xFFFF,0 xFFFE,0x00FC,0x0000,0x07FC,0x3FFF,0xFFFF,
0xF80F,0xFFFF,0xFFFF,0x00FC,0x0000,0x03FC,
0x3FFF,0xFFFF,0xF00F,0xFFFF,0xFFFF,0x00FC,0x0000,0 x01FC,0x1FFF,0xFFFF,0xF007,0xFFFF,0xFFFE,
0x0078,0x0000,0x00F8,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000
} // picture
/*


When using PHPS with the plugin it shows nothing at all - even stranger if I remove "128, 49," from the beginning of the script, all displays correctly.

Any thoughts?