code.php 760 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Tags;
  3. include('lib/geshi/geshi.php');
  4. class code implements ITagProcessor {
  5. private static $LANGUAGE_ALIASES=array(
  6. "c#"=>"csharp",
  7. "html"=>"html5"
  8. );
  9. public static function Process($args, $content) {
  10. if (!isset($args['lang']))
  11. return $content;
  12. if (isset(self::$LANGUAGE_ALIASES[$args['lang']]))
  13. $args['lang']=self::$LANGUAGE_ALIASES[$args['lang']];
  14. if (!isset($args['lineStyle']))
  15. $args['lineStyle']=GESHI_FANCY_LINE_NUMBERS;
  16. else
  17. $args['lineStyle']=(int)$args['lineStyle'];
  18. $content=str_replace("\t", " ", $content);
  19. $geshi=new \GeSHi(trim($content),$args['lang']);
  20. $geshi->enable_line_numbers($args['lineStyle']);
  21. $geshi->set_overall_class("code");
  22. return $geshi->parse_code();
  23. }
  24. }