Skocz do zawartości
  • Przeglądający   0 użytkowników

    Brak zarejestrowanych użytkowników, przeglądających tę stronę.

SeNioR

[Dodatek] Kolorowanie składni kodu ( [code] ) Code Highlight

Promowane odpowiedzi

SeNioR    6,716

Autor: logeen

Opis:

Koloruje w postach na forum składnię dowolnego języka programowania, skryptowego lub innego. Od podobnych tego typu rozwiązań wyróżnia się dodatkowymi cechami:

- Będzie potrafił bez żadnych dodatkowych aktualizacji kolorować składnię języków, które nawet jeszcze nie powstały

- Nie wprowadza nowych znaczników, a kod wykrywa automatycznie w tagach

[code,]...[/code,]
Instrukcja:

otwórz includes/bbcode.php

znajdź:

function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
{
global $lang;

$code_start_html = $bbcode_tpl['code_open'];
$code_end_html = $bbcode_tpl['code_close'];

// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
$match_count = preg_match_all("#\[code](.*?)\[/code] #si", $text, $matches); for ($i = 0; $i ', '"', ':', '[', ']', '(', ')', '{', '}'); $after_replace = str_replace($code_entities_match, $code_entities_replace, $after_replace); $after_replace = str_replace(array('&', '&amp;'), '&', $after_replace); $code_entities_match = array('', '"', ':', '[', ']', '(', ')', '{', '}'); $code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}'); $after_replace = str_replace($code_entities_match, $code_entities_replace, $after_replace); // Replace 2 spaces with "  " so non-tabbed code indents without making huge long lines. $after_replace = str_replace(" ", "  ", $after_replace); // now Replace 2 spaces with "  " to catch odd #s of spaces. $after_replace = str_replace(" ", "  ", $after_replace); // Replace tabs with "   " so tabbed code indents sorta right without making huge long lines. $after_replace = str_replace("\t", "    ", $after_replace); // now Replace space occurring at the beginning of a line $after_replace = preg_replace("/^ {1}/m", ' ', $after_replace); $str_to_match = "
[code]" . $before_replace . "
"; $replacement = $code_start_html; $replacement .= $after_replace; $replacement .= $code_end_html; $text = str_replace($str_to_match, $replacement, $text); } // Now, do all the non-first-level matches. These are simple. $text = str_replace("
", $code_start_html, $text);
$text = str_replace("[/code] ", $code_end_html, $text); return $text; } // bbencode_second_pass_code()[/code] zamień na:
[code]function bbencode_second_pass_code($text, $uid, $bbcode_tpl)
{
global $lang;

$code_start_html = $bbcode_tpl['code_open'];
$code_end_html = $bbcode_tpl['code_close'];

// First, do all the 1st-level matches. These need an htmlspecialchars() run,
// so they have to be handled differently.
$match_count = preg_match_all("#\[code](.*?)\
#si", $text, $matches); for ($i = 0; $i ', '\\\\', '\\"', "\\'", '\\'), array(':', '[', ']', '(', ')', '{', '}', '"', '', '&', '/*'.chr(127).$code_highlight_rand.chr(127).'?*/', '/*'.chr(127).$code_highlight_rand.chr(127).'?php*/', '/*?'.chr(127).$code_highlight_rand.chr(127).'*/', chr(127).($code_highlight_rand+1).chr(127), chr(127).($code_highlight_rand+2).chr(127), chr(127).($code_highlight_rand+3).chr(127), chr(127).($code_highlight_rand+4).chr(127)), $after_replace); $after_replace = preg_replace('//i', ''.chr(127).$code_highlight_rand.'x$1x'.$code_highlight_rand.chr(127).'>', $after_replace); $after_replace = highlight_string('', 1); $after_replace = str_replace(' ', ' ', $after_replace); if (strpos($after_replace, '')) $after_replace = preg_replace(array('/'), $after_replace); $code_highlight_color = preg_match("/(#[0-9A-F]{6})\"><\?/i", $after_replace, $code_highlight_color) ? $code_highlight_color[1] : ''; $after_replace = preg_replace(array("/^(.*)<\?/iseU", "/\?>(.*)$/iseU"), array('str_replace("\n", "", "$1")', 'str_replace("\n", "", "$1")'), $after_replace); // Make PHP functions links: include_once($phpbb_root_path . 'includes/code_highlight_php.php'); $after_replace_tmp = preg_replace_callback('/\/\*'.chr(127).$code_highlight_rand.chr(127).'\?\*\/.*\/\*\?'.chr(127).$code_highlight_rand.chr(127).'\*\//sU', 'code_highlight_php', $after_replace); if (!is_null($after_replace_tmp)) $after_replace = $after_replace_tmp; $after_replace = str_replace(array('/*'.chr(127).$code_highlight_rand.chr(127).'?*/', '/*'.chr(127).$code_highlight_rand.chr(127).'?php*/', '/*?'.chr(127).$code_highlight_rand.chr(127).'*/', chr(127).($code_highlight_rand+1).chr(127), chr(127).($code_highlight_rand+2).chr(127), chr(127).($code_highlight_rand+3).chr(127), chr(127).($code_highlight_rand+4).chr(127)), array('<?', '<?php', '?>', '\\\\', '\\"', "\\'", '\\'), $after_replace); $after_replace = preg_replace(array('/'.chr(127).$code_highlight_rand.'x(script)x'.$code_highlight_rand.chr(127).'/i', "/#[0-9A-F]{6}\">([ \t\n]*#[0-9A-F]{6}\">[^]+[ \t\n]*)/i", "/#[0-9A-F]{6}\">([ \t\n]*)/i"), array('$1', '$1', '$1'), $after_replace); // Make tab marks: $after_replace = preg_replace("/> ( *)/i", '>$1', $after_replace); // Make line numeration: $after_replace_lines = spliti("
= 0; $code_highlight_j--) { } $code_highlight_tmp .= $code_highlight_num_tmp . '' . $after_replace_lines[$code_highlight_i]; if ($code_highlight_i
", $code_start_html, $text);
$text = str_replace("[/code] ", $code_end_html, $text); return $text; } // bbencode_second_pass_code()[/code]

[center][b]Plik z załącznika wgraj do folderu includes[/b][/center]

code_highlight_php.rar

" . $before_replace . "
";
        $replacement = $code_start_html;
        $replacement .= $after_replace;
        $replacement .= $code_end_html;
        $text = str_replace($str_to_match, $replacement, $text);
    }
    // Now, do all the non-first-level matches. These are simple.
    $text = str_replace("

Udostępnij tego posta


Odnośnik do posta
Udostępnij na innych stronach
Gość
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.

×