Super, ale to dla mnie za bardzo zaawansowane,
Zanim dojdę co i jak to ruski rok minie.
Udało mi się znaleźć coś takiego
class ColorSyntax {
public function SearchCode($content) {
$content = preg_replace("#\[code lang=\"(.*?)\"\]\'\(.*?)\[\/code\]#sie", '$this->PreformBlock("\\1","\\2");', $content);
return $content;
}
public function PreformBlock($lang, $source){
$result = $this->HighlightCode($source, $lang);
return $result;
}
public function ParseCode($content){
return $this->SearchCode($content);
}
public function HighlightCode($source, $lang ){
$geshi = new GeSHi($source, $lang);
$geshi->set_source($source);
$result = $geshi->set_language($lang);
$result = $geshi->parse_code();
return $result;
}
}
Problem jest tylko w tym, że jeśli między znacznikami [code lang="php"] wystąpią pojedyncze cudzysłowy lub podwójne to rozwala się cała strona
przykład
$POST='
[code lang="bash"]
#!/bin/bash
plik="/tmp/dane_db.txt"
if [ 'ddd' -ge "dd" ]; then
';
i niestety staje na linijce if , macie pomysł jak to poprawić ?