User Tools

Site Tools


products:stewgeshi

geSHi

Do you want to display formatted code in your posts?

Are you tired of your code getting destroyed by the fox?

Does this page make you drool ? http://qbnz.com/

Drool no more, we have finally integrated geSHi into fox.

It was a long journey http://stewfoxdev.com/v3/index.php?do=/forum/thread/12/geshi-latest-battles/

Install

Unzip and copy upload to your site. Same as always.

Edit the forum post template

We found the split modifier destroyed geSHi output. We did not bother looking into it.

Save that for futures. Here we just remove it.

/module/forum/template/MYTHEME/block/post.html.php

			<div class="forum_content{if (isset($aPost.view_id) && $aPost.view_id && !isset($sView)) || (isset($sView) && $sView != 'pending-post')} row_moderate{/if} item_view_content" id="js_post_edit_text_{$aPost.post_id}">

                {$aPost.text|parse}
                {*** dsm 15 jan 15
                    Wow. Major problem with splitting output from geshi
                    Don't have time to look into that now.
                    Cut it off at the knees.
                {$aPost.text|parse|split:55}
                ***}
			</div>

Edit the input class

If you wish to avoid modifying the core, you may avoid editing the source by using stewload.

/include/library/phpfox/parse/input.class.php

Add code at the top of this method.

And add code at the end, replacing the return value.

	/**
	 * Prepare text strings. Used to prepare all data that can contain HTML. Not only does
	 * it protect against harmful HTML and CSS, it also has support for emoticon and BBCode conversion.
	 *
	 * @param string $sTxt Text to parse.
	 * @return string Parsed string.
	 */
	public function prepare($sTxt, $bNoClean = false)
	{
            // dsm 15 jan 15 : stewfoxdev.com needs a hook here for using GESHI code formatting
            // There is no need to clean the output from geshi. Attempting the feat will cause havoc.
            $sTxt =  Phpfox::getService('stewgeshi.parse')->preCodeBlock($sTxt);

            ...(snip body of this method)...

            // dsm 15 jan 15 : stewfoxdev.com needs a hook here for using GESHI code formatting
            return Phpfox::getService('stewgeshi.parse')->postCodeBlock($sTxt);
	    // return $sTxt;
	}

Usage

I need to get some screen prints here. My styling is too ugly to show.

Simple case. Just code

Wrap code in the square bracket quasi XML notation shown below. Pow! It is pretty and safe.

PHP can be upper or lower case. I can be any of the sixty or more languages supported by geSHi !!

At fox we'll use mostly php, javascript,css and html.

[PHP]
$x=1;
[/PHP]

Highlight some lines

To point out lines of interest in context, geSHi will show the in a different styling.

The syntax show below will highlight lines 6 through 10 of a ruby snippet.

Single line number, or ranges separated by a hyphen: 77, 5-10, 82

Order is unimportant. Delimit the list with spaces or commas (but not both) EG 1,2,3 or 1 2 3

[ruby 6-10]
grade = 10
school = case grade
when 0..5
   "elementary"
when 6..8
   "middle school"
when 9..12
   "high school"
else
   "college"
end
puts "grade #{grade} is in #{school}"
[/ruby]

Show line numbers

Use an L (any case) to indicate you want every line numbered.

[javascript L]

$Behavior.bad= austin || {};

austen:behave = 'baby';

[/javascript]

Known anomaly I am not able to use L and line highlighting together. Either I can hilite some line or I can have all lines numbered. Not sure yet where that is coming from. Needs more time to investigate.

Futures / Notes

Fox went seriously berserk around the time they introduced the HTML Purifier. One can only guess many of their sites were hacked by malicious user input.

Now you cannot even put a style in your own template without fox stripping it away. That is truly bizarre.

There's a mountain of investigation to be done to unscrew this issue, and it's just not worth the time and effort.

We notice default forum css has forced (!important) styling for line height.

Rules about what is acceptable are buried in various places. They'll be different per site.

The fox even strips HTML comments. It's crazy.

At the moment it looks like a standoff. geSHi uses inline styles and fox strips them. More research is needed.

Many geSHi options could be surfaced in the adminCP. There are a lot of them!

Credits

GeSHIi Authors:

  
      © 2004 - 2007 Nigel McNie
      © 2007 - 2012 Benny Baumann
      © 2008 - 2009 Milian Wolff
      

GeSHi Websites:

THE DOCS http://qbnz.com/highlighter

THE SOURCE https://github.com/GeSHi/

Status

Works for me. Limited testing today. Packaged as a module for release. Ready for beta testers.

Not used in production. Initial release 2015.01.15

With line numbers, hilighting and all supported geSHi languages 2015.01.16

products/stewgeshi.txt · Last modified: 2015/01/16 15:04 by steward