| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
class myToolkit |
|---|
| 4 |
{ |
|---|
| 5 |
private static function geshiCall($matches, $default = '') |
|---|
| 6 |
{ |
|---|
| 7 |
require_once('geshi.php'); |
|---|
| 8 |
|
|---|
| 9 |
if (preg_match('/^\[(.+?)\]\s*(.+)$/s', $matches[1], $match)) |
|---|
| 10 |
{ |
|---|
| 11 |
$geshi = new GeSHi(html_entity_decode($match[2]), $match[1]); |
|---|
| 12 |
$geshi->enable_classes(); |
|---|
| 13 |
return @$geshi->parse_code(); |
|---|
| 14 |
} |
|---|
| 15 |
else |
|---|
| 16 |
{ |
|---|
| 17 |
if ($default) |
|---|
| 18 |
{ |
|---|
| 19 |
$geshi = new GeSHi(html_entity_decode($matches[1]), $default); |
|---|
| 20 |
$geshi->enable_classes(); |
|---|
| 21 |
|
|---|
| 22 |
return @$geshi->parse_code(); |
|---|
| 23 |
} |
|---|
| 24 |
else |
|---|
| 25 |
{ |
|---|
| 26 |
return "<pre><code>".$matches[1].'</pre></code>'; |
|---|
| 27 |
} |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
private static function geshiCallWithPHPAsDefault($matches) |
|---|
| 32 |
{ |
|---|
| 33 |
return self::geshiCall($matches, 'php'); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
public static function transformToHtml($string) |
|---|
| 37 |
{ |
|---|
| 38 |
$string = htmlentities($string, ENT_QUOTES, 'UTF-8'); |
|---|
| 39 |
|
|---|
| 40 |
$lines = explode("\n", $string); |
|---|
| 41 |
$incode = false; |
|---|
| 42 |
$string = ''; |
|---|
| 43 |
foreach ($lines as $line) |
|---|
| 44 |
{ |
|---|
| 45 |
if ($incode) |
|---|
| 46 |
{ |
|---|
| 47 |
$line = ' '.html_entity_decode($line, ENT_QUOTES, 'UTF-8'); |
|---|
| 48 |
} |
|---|
| 49 |
if (preg_match('/^\s*\[code\s*([^\]]*?)\]/', $line, $match)) |
|---|
| 50 |
{ |
|---|
| 51 |
$incode = true; |
|---|
| 52 |
$line = $match[1] ? "\n\n [".$match[1]."]" : "\n\n"; |
|---|
| 53 |
} |
|---|
| 54 |
if (strpos($line, '[/code]') !== false) |
|---|
| 55 |
{ |
|---|
| 56 |
$incode = false; |
|---|
| 57 |
$line = ' '; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
$string .= $line."\n"; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
require_once('markdown.php'); |
|---|
| 65 |
$html = markdown($string); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
$html = preg_replace('/<pre><code>\$ /s', '<pre class="command-line"><code>$ ', $html); |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
$html = preg_replace('#<pre><code>http\://#s', '<pre class="url"><code>http://', $html); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
$html = preg_replace_callback('#<pre><code>(.+?)</code></pre>#s', array('myToolkit', 'geshiCallWithPHPAsDefault'), $html); |
|---|
| 75 |
|
|---|
| 76 |
return $html; |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
?> |
|---|