• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

GeSHi Syntax Highlighter

Status
Not open for further replies.

digitalpoint

Well-known member
About
This is a GeSHi based syntax highlighter that intercepts CODE, HTML and PHP BBCode and formats them to be "pretty".

Installation
  • Put the contents of the library directory into your XenForo library directory.
  • Install the addon-dpSyntaxHighlighter.xml file in your Admin Control Panel -> Install Add-on option.
Usage
  • For PHP and HTML highlighting, nothing special is needed, just use the normal [php] and [html] BBCode.
  • If you want to specify a specific language to highlight, you can use the [code] BBCode with an option like so: [code=javascript]
Notes
  • All languages that GeSHi supports are supported (currently 201).
  • There is one option that is added to the "Messages" section of XenForo options. (Show Line Numbers In Parsed BBCode)
geshi.webp
 

Attachments

Ohhh nice!!! All shiny and stuff...and still has that new mod smell. :-)

Im'a try it out today.

Thanks for this...can't wait to play around with it :-)
 
It will only run the GeSHi code/class when there is actual PHP, CODE or HTML BBCode that need to be parsed. If a page has none if it, it should not affect page generation time. If it does, then obviously there will be a little overhead for it since it needs to parse/process it. It would be nice if XF stored pre-parsed posts (then it would just have to parse the post once, and be done with it), but currently they do not. I already made a feature request for storing parsed posts over here.
 
Code Test:
PHP:
if (var == true)
{
    document.write('hello world');
}

>>>>formats them to be "pretty" <<<
Define pretty.
xF seems to natively colo(u)rize.
 
Not for everything, nor does it have line numbering for example. This just extends on what xenforo already does.

Great stuff DigitalPoint
 
Excellent Shawn! Thanks... This is one of two things I needed to convert to XF. I was really very very reluctant (as always) to code this myself... :)

Thanks again! (y)

To the guy who was saying XF already has pretty code, XF doesn't support all languages. I need this specifically for SQL, as I run an Oracle Forum... I have customized the old code highlighting addon on VB to have an editor button like PHP and HTML here called SQL where you can select the code and press the SQL button for SQL highlighting with [SQL] [/SQL]. I will be doing the same for this one for XF! Now if only Kier would release that magical Resource Manager which I plan to use as a Downloads addon, I could quickly migrate... :D
 
It will only run the GeSHi code/class when there is actual PHP, CODE or HTML BBCode that need to be parsed. If a page has none if it, it should not affect page generation time. If it does, then obviously there will be a little overhead for it since it needs to parse/process it. It would be nice if XF stored pre-parsed posts (then it would just have to parse the post once, and be done with it), but currently they do not. I already made a feature request for storing parsed posts over here.
Shawn,
Can this addon be modified so that the code button in XF editor has the additional languages added to its dropdown list. Right now, it has General code, PHP and HTML. Would be nice if we can arrange the order of this list so the languages most used at our own forum are on top.
 
Probably wouldn't be too difficult, but I think you then risk making it cluttered and less usable if you have 201 languages in the drop-down list.
 
If you want to add additional languages you pick to the dialog, you need to make 2 changes... First you would need to edit the js/tinymce/themes/xenforo/js/code.js file and change this:
Code:
default:     tag = 'CODE';
to this:
Code:
default:     tag = $('#ctrl_type').val();
Unfortunately there's not a way around the JavaScript file edit...

The other change would be to edit the editor_dialog_code template to add whatever specific languages you want to the <select> element. For example:

Code:
<option value="code=javascript">JavaScript</option>
<option value="code=ruby">Ruby</option>
<option value="code=sql">SQL</option>
etc...
 
Probably wouldn't be too difficult, but I think you then risk making it cluttered and less usable if you have 201 languages in the drop-down list.
Ideally, the list of language will be in the ACP Options where it has a textbox and you can enter things like
cpp, java, csharp, sql, php, python
And the dropdown will show those in that exact order.

EDIT: Got ninja'd by Shawn why I was typing.
 
Status
Not open for further replies.
Top Bottom