Changing the code tag

Started by BadW0lf, February 21, 2012, 03:04:47 AM

Previous topic - Next topic

BadW0lf

I run a website related to the development of Minecraft, and I need to change the code tag so it's more readable.

I'm trying to use alexgorbatchev's SyntaxHighlighter.

Why are there two code tags defined in the Subs.php file? Which one do I edit to make this work?

Thanks!

kat

Welcome to the ol' forum, BadW0lf!

More readable, how?

Text size? Colour?

Have a look at index.css, in the theme's "css" directory. ;)

Maybe this bit?

/* A code block - maybe PHP ;). */
code.bbc_code
{
display: block;
font-family: "dejavu sans mono", "monaco", "lucida console", "courier new", monospace;
font-size: x-small;
background: #eef;
border-top: 2px solid #999;
border-bottom: 2px solid #999;
line-height: 1.5em;
padding: 3px 1em;
overflow: auto;
white-space: nowrap;
/* Show a scrollbar after about 24 lines. */
max-height: 24em;
}

/* The "Quote:" and "Code:" header parts... */
.codeheader, .quoteheader
{
color: #666;
font-size: x-small;
font-weight: bold;
padding: 0 0.3em;
}

emanuele

Quote from: BadW0lf on February 21, 2012, 03:04:47 AM
Why are there two code tags defined in the Subs.php file? Which one do I edit to make this work?
There are two because one is for when you do:
[code]my code here[/code]

and the other is for the case:
[code=somethinghere]my code here[/code]

BTW, if you have a look at the mod site there are a couple of syntax highlighting mods, maybe one of the two could help you. :)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

BadW0lf

Quote from: emanuele on February 21, 2012, 08:09:37 AM
Quote from: BadW0lf on February 21, 2012, 03:04:47 AM
Why are there two code tags defined in the Subs.php file? Which one do I edit to make this work?
There are two because one is for when you do:
[code]my code here[/code]

and the other is for the case:
[code=somethinghere]my code here[/code]

BTW, if you have a look at the mod site there are a couple of syntax highlighting mods, maybe one of the two could help you. :)

On using the GeSHi one, how would I make it so it automatically parsed everything as Java?

emanuele

Not tested!

I left a comment in the code about a setting (highlight_lines_extra).

Code (find) Select
array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
// @todo Maybe this can be simplified?
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context;

if (!isset($disabled[\'code\']))
{
$php_parts = preg_split(\'~(&lt;\?php|\?&gt;)~\', $data, -1, PREG_SPLIT_DELIM_CAPTURE);

for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
{
// Do PHP code coloring?
if ($php_parts[$php_i] != \'&lt;?php\')
continue;

$php_string = \'\';
while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?&gt;\')
{
$php_string .= $php_parts[$php_i];
$php_parts[$php_i++] = \'\';
}
$php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
}

// Fix the PHP code stuff...
$data = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));

// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
else
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);

// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \'&nbsp;\';
}'),
'block_level' => true,
),


Code (replace with) Select
array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
// @todo Maybe this can be simplified?
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context, $sourcedir, $settings, $txt;

if (!isset($disabled[\'code\']))
{
$geshi = new Geshi($data, \'java\');
if ($geshi->error()) {
$lang = "text";
$geshi->set_language($lang, true);
}
$geshi->set_overall_class(\'geshi\');

$geshi->start_line_numbers_at($start_number);

/*
// This is something you can set
// if you want to have a default remove the comments
// and replace PUT_YOUR_SETTING_HERE with the value you want
if (strlen(trim($settings[\'geshi_highlight_lines_extra_style\'])))
$geshi->set_highlight_lines_extra_style($settings[\'geshi_highlight_lines_extra_style\']);
$geshi->highlight_lines_extra(PUT_YOUR_SETTING_HERE);
}
*/

$geshi->set_overall_class(\'geshi\');
$geshi->set_header_type($settings[\'geshi_code_container\']);

$geshi->enable_line_numbers($settings[\'geshi_line_numbers\'], $settings[\'geshi_fancy_line_number\']);
$geshi->set_line_style($settings[\'geshi_line_style\'], $settings[\'geshi_line_style_fancy\']);

$pre_header = "";
if ($settings[\'geshi_enable_pre_header\']) {
$pre_header = \'<div class="codeheader">\' . str_replace(array("{CODE}", "{TAG}", "{LANGUAGE}"), array($txt[\'code\'], strtoupper($lang), $geshi->get_language_name()), $settings[\'geshi_pre_header\']) . "</div>";
}

if ($settings[\'geshi_enable_header\']) {
$geshi->set_header_content($settings[\'geshi_header\']);
}
               
if ($settings[\'geshi_enable_footer\']) {
$geshi->set_footer_content($settings[\'geshi_footer\']);
}

$data = $pre_header . str_replace("\n", "", $geshi->parse_code());

// Dont\' know if this is needed with GeSHi too, but for a space...
// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \'&nbsp;\';
}'),
'block_level' => true,
),


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

BadW0lf

#5
Quote from: emanuele on February 21, 2012, 05:29:32 PM
Not tested!

I left a comment in the code about a setting (highlight_lines_extra).

Code (find) Select
array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
// @todo Maybe this can be simplified?
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context;

if (!isset($disabled[\'code\']))
{
$php_parts = preg_split(\'~(&lt;\?php|\?&gt;)~\', $data, -1, PREG_SPLIT_DELIM_CAPTURE);

for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
{
// Do PHP code coloring?
if ($php_parts[$php_i] != \'&lt;?php\')
continue;

$php_string = \'\';
while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?&gt;\')
{
$php_string .= $php_parts[$php_i];
$php_parts[$php_i++] = \'\';
}
$php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
}

// Fix the PHP code stuff...
$data = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));

// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
else
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);

// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \'&nbsp;\';
}'),
'block_level' => true,
),


Code (replace with) Select
array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . (isBrowser('gecko') || isBrowser('opera') ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . (isBrowser('gecko') || isBrowser('opera') ? '</pre>' : ''),
// @todo Maybe this can be simplified?
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context, $sourcedir, $settings, $txt;

if (!isset($disabled[\'code\']))
{
$geshi = new Geshi($data, \'java\');
if ($geshi->error()) {
$lang = "text";
$geshi->set_language($lang, true);
}
$geshi->set_overall_class(\'geshi\');

$geshi->start_line_numbers_at($start_number);

/*
// This is something you can set
// if you want to have a default remove the comments
// and replace PUT_YOUR_SETTING_HERE with the value you want
if (strlen(trim($settings[\'geshi_highlight_lines_extra_style\'])))
$geshi->set_highlight_lines_extra_style($settings[\'geshi_highlight_lines_extra_style\']);
$geshi->highlight_lines_extra(PUT_YOUR_SETTING_HERE);
}
*/

$geshi->set_overall_class(\'geshi\');
$geshi->set_header_type($settings[\'geshi_code_container\']);

$geshi->enable_line_numbers($settings[\'geshi_line_numbers\'], $settings[\'geshi_fancy_line_number\']);
$geshi->set_line_style($settings[\'geshi_line_style\'], $settings[\'geshi_line_style_fancy\']);

$pre_header = "";
if ($settings[\'geshi_enable_pre_header\']) {
$pre_header = \'<div class="codeheader">\' . str_replace(array("{CODE}", "{TAG}", "{LANGUAGE}"), array($txt[\'code\'], strtoupper($lang), $geshi->get_language_name()), $settings[\'geshi_pre_header\']) . "</div>";
}

if ($settings[\'geshi_enable_header\']) {
$geshi->set_header_content($settings[\'geshi_header\']);
}
               
if ($settings[\'geshi_enable_footer\']) {
$geshi->set_footer_content($settings[\'geshi_footer\']);
}

$data = $pre_header . str_replace("\n", "", $geshi->parse_code());

// Dont\' know if this is needed with GeSHi too, but for a space...
// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \'&nbsp;\';
}'),
'block_level' => true,
),


It doesn't like it :/

Fatal error: Call to undefined function isBrowser() in /home/ziddia/public_html/smf/Sources/Subs.php on line 1083

Edit: I got rid of that error by using $context['browser'] rather than isBrowser, and the appropreate function (is_opera, is_gecko)

Now it's saying Class Geshi can not be found on line 1134... I did install that package.

Matthew K.

Is the class definition on line 1134?

BadW0lf

Quote from: Labradoodle-360 on February 22, 2012, 12:39:04 AM
Is the class definition on line 1134?

Lines 1080 - 1136:

array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
// @todo Maybe this can be simplified?
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context, $sourcedir, $settings, $txt;

if (!isset($disabled[\'code\']))
{
$geshi = new Geshi($data, \'java\');
if ($geshi->error()) {
$lang = "text";
$geshi->set_language($lang, true);
}
$geshi->set_overall_class(\'geshi\');

$geshi->start_line_numbers_at($start_number);

/*
// This is something you can set
// if you want to have a default remove the comments
// and replace PUT_YOUR_SETTING_HERE with the value you want
if (strlen(trim($settings[\'geshi_highlight_lines_extra_style\'])))
$geshi->set_highlight_lines_extra_style($settings[\'geshi_highlight_lines_extra_style\']);
$geshi->highlight_lines_extra(PUT_YOUR_SETTING_HERE);
}
*/

$geshi->set_overall_class(\'geshi\');
$geshi->set_header_type($settings[\'geshi_code_container\']);

$geshi->enable_line_numbers($settings[\'geshi_line_numbers\'], $settings[\'geshi_fancy_line_number\']);
$geshi->set_line_style($settings[\'geshi_line_style\'], $settings[\'geshi_line_style_fancy\']);

$pre_header = "";
if ($settings[\'geshi_enable_pre_header\']) {
$pre_header = \'<div class="codeheader">\' . str_replace(array("{CODE}", "{TAG}", "{LANGUAGE}"), array($txt[\'code\'], strtoupper($lang), $geshi->get_language_name()), $settings[\'geshi_pre_header\']) . "</div>";
}

if ($settings[\'geshi_enable_header\']) {
$geshi->set_header_content($settings[\'geshi_header\']);
}
               
if ($settings[\'geshi_enable_footer\']) {
$geshi->set_footer_content($settings[\'geshi_footer\']);
}

$data = $pre_header . str_replace("\n", "", $geshi->parse_code());

// Dont\' know if this is needed with GeSHi too, but for a space...
// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \'&nbsp;\';
}'),
'block_level' => true,
),


Also, full error:

Fatal error: Class 'Geshi' not found in /home/ziddia/public_html/smf/Sources/Subs.php(1134) : runtime-created function on line 6

Matthew K.

You have to require the Geshi class file somewhere in the BBC function above the array.

BadW0lf

#9
It appears the GeSHi plugin does not work.

With no changes, it gives

QuoteFatal error: Cannot redeclare class GeSHi in /home/ziddia/public_html/smf/Sources/geshi.php on line 259

Edit: I'm using another one now.
It's working fine.

emanuele

Quote from: BadW0lf on February 22, 2012, 12:05:45 AM
Fatal error: Call to undefined function isBrowser() in /home/ziddia/public_html/smf/Sources/Subs.php on line 1083
Sorry, I took the code from the wrong directory... :-[


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

BadW0lf

Quote from: emanuele on February 22, 2012, 05:36:04 AM
Quote from: BadW0lf on February 22, 2012, 12:05:45 AM
Fatal error: Call to undefined function isBrowser() in /home/ziddia/public_html/smf/Sources/Subs.php on line 1083
Sorry, I took the code from the wrong directory... :-[

I got it working with another package.

Thanks for the help, though!

kat


Advertisement: