Page 1 of 1

GeSHi Syntax Highlighter installation

Posted: Wed Jul 11, 2018 5:13 pm
by Raheem
Hello,

I was trying to install GeSHi Syntax Highlighter in my phpBB 3.2.2 forum, i need to highligh the code to C#. When user use [code][/code] tag it automatically use C# as default language.

I follow installation from here: http://qbnz.com/highlighter/geshi-doc.html

I first upload geshi.php and geshi folder to includes folder. Then opened: bbcode.php and edited:

Code: Select all

	/**
	* Second parse code tag
	*/
	function bbcode_second_pass_code($type, $code)
	{
		// when using the /e modifier, preg_replace slashes double-quotes but does not
		// seem to slash anything else
		$code = str_replace('\"', '"', $code);

		switch ($type)
		{
			case 'php':
				// Not the english way, but valid because of hardcoded syntax highlighting
				if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
				{
					$code = substr($code, 41);
				}

			// no break;

			default:
				$code = str_replace("\t", '&nbsp; &nbsp;', $code);
				$code = str_replace('  ', '&nbsp; ', $code);
				$code = str_replace('  ', ' &nbsp;', $code);
				$code = str_replace("\n ", "\n&nbsp;", $code);

				// keep space at the beginning
				if (!empty($code) && $code[0] == ' ')
				{
					$code = '&nbsp;' . substr($code, 1);
				}

				// remove newline at the beginning
				if (!empty($code) && $code[0] == "\n")
				{
					$code = substr($code, 1);
				}
			break;
		}

		$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');

		return $code;
	}
To:

Code: Select all

	/**
	* Second parse code tag
	*/
	function bbcode_second_pass_code($type, $code)
	{
		include_once('geshi.php');
		
		$geshi = new GeSHi($code, 'csharp');
		
		$code = $geshi->parse_code();

		$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');

		return $code;
	}
This according to http://qbnz.com/highlighter/geshi-doc.html but it did not work, nothing highlighted why? is there is something i miss? i don't know in php but it seems like other languages i know like java.

Re: GeSHi Syntax Highlighter installation

Posted: Thu Jul 12, 2018 7:55 am
by AmigoJack
Raheem wrote:
Wed Jul 11, 2018 5:13 pm
is there is something i miss?
Yes:
  • The manual's most recent date is "© 2007 - 2012", which means it can only be interpreted for phpBB versions in that date, not today.
  • The manual clearly says "mod for phpBB", but MOD support died along with the 3.0.x branch - today's 3.2.x does not support them anymore.

Re: GeSHi Syntax Highlighter installation

Posted: Thu Jul 12, 2018 11:29 am
by Raheem
That's OK Amigo, thanks.