GeSHi Plugin .02 released

Creating and modifying plugins.
Post Reply
User avatar
gizmola
Regular
Posts: 37
Joined: Mon Oct 25, 2004 11:54 pm

GeSHi Plugin .02 released

Post by gizmola » Sat Apr 02, 2005 1:33 pm

This is more or less the fully functional generic syntax high lighting plugin, including line numbering options, as I initially planned.

I committed the source code to cvs tonight, so it should be available tommorrow.

Here's the readme:

------------------------
About
------------------------
This plugin allows you to embed code snippets from various computer languages in your articles,
and have the code color/syntax hi-lighted, and optionally have the lines numbered. Line numbering
is done with styles so visitors can still cut and paste your code, without having the line numbers
interfere with the code.

It is based on the GeSHi generic syntax highlighter library (included with the plugin). GeSHi's
home page is http://qbnz.com/highlighter/.

The GeSHi plugin was written by David Rolston. If you have questions or suggestions, you can
visit my website forum, available from my homepage -> http://www.gizmola.com/


------------------------
Upgrades
------------------------
If you are replacing version .01, you will either have to uninstall and reinstall the Geshi plugin, or
use the http://yourblog/admin to go into the geshi plugin configuration screen and re-save the settings.
This was necessitated by the addition of the geshi path configuration item which was previously hardcoded.

------------------------
How to use
------------------------
1.Enable this event plugin.

2. You should make sure that it comes before the NL2BR plugin. I'd also suggest you order it
before the BBCode Plugin.

3. The default settings should be best for most people, with the possible exception of the
"showlinenumbers" setting, which defaults to off. If you turn this setting on, your geshi
blocks will include line numbers without you having to manually override line numbering to on.

When you want to enclose a block use this syntax:

[geshi lang=name] Code here [/geshi]

For a list of supported languages and the language name to use, look in the /geshi directory. Each supported
language has a name.php file.

Here's a few of the more popular decodes:
c - (C language)
cpp (C++)
java
php
actionscript
javascript
python
css
sql

Each Article can have as many geshi blocks as desired. There is no problem having multiple geshi blocks
with different languages in the same article.

------------------------
Override line numbering
------------------------
If you want to add or remove line numbering explicitly, you can use the optional ln= parameter.
The options are ln={y|n} where y = yes (on) and n = no (off). So for example, to turn on line numbering
in a php block you would use:

[geshi lang=php ln=y]...php code [/geshi]

Unlike html, the ln parameter must come AFTER the lang parameter.

------------------------
Known issues
------------------------
This version is now stable beta!!! Use at your own risk (although risks are probably minimal).

-Line numbering will start on the tag line, so if you don't want extra blank numbered lines, code must
immediately follow the block tag.

-Unlike html, the ln parameter must come AFTER the lang parameter. If you use ln= first, your geshi
block will not work.

------------------------
An Example (c++)
------------------------

[geshi lang=cpp]
double CAAPluto::EclipticLongitude(double JD)
{
double T = (JD - 2451545) / 36525;
double J = 34.35 + 3034.9057*T;

//Calculate Longitude
double L = 0;
int nPlutoCoefficients = sizeof(g_PlutoArgumentCoefficients) / sizeof(PlutoCoefficient1);
for (int i=0; i<nPlutoCoefficients; i++)
{
double Alpha = g_PlutoArgumentCoefficients[i].J * J + g_PlutoArgumentCoefficients[i].S * S + g_PlutoArgumentCoefficients[i].P * P;
Alpha = CAACoordinateTransformation::DegreesToRadians(Alpha);
L += ((g_PlutoLongitudeCoefficients[i].A * sin(Alpha)) + (g_PlutoLongitudeCoefficients[i].B * cos(Alpha)));
}
L = L / 1000000;
L += (238.958116 + 144.96*T);
L = CAACoordinateTransformation::MapTo0To360Range(L);

return L;
}
[/geshi]

MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy » Thu Jun 16, 2005 10:58 am

this is good work :)
Geshi allows u to change color and all, and have fancy line numbes. Any note if there is an updated Geshi plugin avilable

plus in WYSIWYG it starts to parse my XML file, How can i stop it from doing that. can't use code cause Geshi then color codes the <code></code> tag.

plus switching back to WYSIWYG and going back to html mode it strips the <?xml version='1.0' encoding='utf-8'?>
tag from my XML.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Jun 16, 2005 2:46 pm

GesHi will not work in WYSIWYG environments for those XML highlighting, I'm sorry. There is no way to surround this, as the WYSIWYG interprets HTML/XML.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy » Fri Jun 17, 2005 1:49 pm

So this occurs cause i'm using XML, :cry:

There is a plugin in serendipity that can do color coding this way, with scrollbars :P
http://toys.lerdorf.com/archives/30-Syn ... l#comments

Do u know which plugin is that. I saw a similar plugin written for WP using Text_hilighter from pear. http://www.chroder.com/archives/2005/04 ... ht-plugin/

MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy » Mon Jun 20, 2005 12:27 pm

any one. know about that

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Mon Jun 20, 2005 12:31 pm

What you see there on Rasmus' blog is a simple iframe that points to a .phps file:

<iframe src="http://lerdorf.com/synci.phps" width="100%" height="250">

The color coding is done by PHP itself if .phps support is activated in your webserver.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy » Mon Jun 20, 2005 1:32 pm

ok,yeah i just looked at the source code of it
but do u know of any plugin in serendipity that is similar to codehighlight plugin in WP. code coloring inside a box with scrollbars.

plus is there any reason why a WP plugin won't work in S9y.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Mon Jun 20, 2005 1:40 pm

That can be done easily with CSS. All the bbcode and other code plugins emit a div.bbcode or something like that. You can then use:

Code: Select all

.bbcode {
overflow: scroll;
width: 100px;
height: 100px;
}


And there is a reason why WP plugins do not work with Serendipity: They have absolutely nothing in common. That's like asking, why does the engine of a Boeing 747 not work in my Porsche Carrera? ;-)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

MySchizoBuddy
Regular
Posts: 340
Joined: Sun Jun 12, 2005 5:28 am

Post by MySchizoBuddy » Tue Jun 28, 2005 11:47 pm

Sanku garvin
me looked into it and Geshi spits out div.lang tag where lang is the language ur using
so for xml code, it will spit out div.xml, for php its div.php, which is just weird.

so then using

.xml {
background-color: #F9FBFC;
border: 2px solid #C3CED9;
padding: 8px;
margin-bottom: 5px;
width: 500px;
overflow:scroll;
text-align: left;
}

does the job except it wordwraps anything inside the scrolling box, It shouldn't wordwrap just create a horizontal scrolling bar.
anyway to stop the wordwrap

plus how can I set a max #of text lines after which a scroll must be added.
So a 2 line code won't have any scroll and the window height will be only 2*lineheight something.

but if the code is 50 lines then add scroll, but restrict the window height to 20*lineheight, not 50*lineheight

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Wed Jun 29, 2005 10:38 am

Try to remove the "width:" attribute of your .xml class. And then set "overflow: auto" for your second problem. :)

You cannot do the last one, conditional heights with CSS.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply