cssbuild.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. error_reporting(0);
  3. /**
  4. * Automatically build CSS stylesheet definitions from GeSHi files
  5. *
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. */
  8. // fix the directory if needed:
  9. $files = glob('geshi-1.0/src/geshi/*.php');
  10. fwrite(STDERR,"step 1: finding style usage counts...\n");
  11. $counts = array();
  12. foreach($files as $file){
  13. include($file);
  14. foreach($language_data['STYLES'] as $type => $styles){
  15. foreach($styles as $style => $css){
  16. $counts[$type.$style][$css] += 1;
  17. }
  18. }
  19. }
  20. print_r($counts);
  21. fwrite(STDERR,"step2: finding most common styles...\n");
  22. $common = array();
  23. foreach($counts as $type => $styles){
  24. asort($styles);
  25. $style = array_pop(array_keys($styles));
  26. $count = array_pop(array_values($styles));
  27. if($count > 1 && !empty($style)){
  28. $common[$type] = $style;
  29. }
  30. }
  31. ksort($common);
  32. fwrite(STDERR,"step3: finding styles different fromt the common ones...\n");
  33. $diff = array();
  34. foreach($files as $file){
  35. include($file);
  36. $lang = basename($file,'.php');
  37. foreach($language_data['STYLES'] as $type => $styles){
  38. foreach($styles as $style => $css){
  39. if(!empty($css) && $common[$type.$style] != $css){
  40. $diff[$lang][$type.$style] = $css;
  41. }
  42. }
  43. if(is_array($diff[$lang])) ksort($diff[$lang]);
  44. }
  45. }
  46. ksort($diff);
  47. fwrite(STDERR,"step4: creating CSS styles...\n\n");
  48. echo "/* Common Code highlighting styles */\n\n";
  49. foreach($common as $name => $style){
  50. echo '.code .'.classname($name).' { '.$style.' }'."\n";
  51. }
  52. echo "\n\n/* additional language styles */\n\n";
  53. foreach($diff as $lang => $styles){
  54. echo "\n/* $lang overrides */\n";
  55. foreach($styles as $name => $style){
  56. echo '.code.'.$lang.' .'.classname($name).' { '.$style.' }'."\n";
  57. }
  58. }
  59. // helper to build the short class names
  60. function classname($name){
  61. $name = str_replace('KEYWORDS','kw',$name);
  62. $name = str_replace('COMMENTSHARD','co_h',$name);
  63. $name = str_replace('COMMENTS','co',$name);
  64. $name = str_replace('BRACKETS','br',$name);
  65. $name = str_replace('ESCAPE_CHAR','es',$name);
  66. $name = str_replace('STRINGSHARD','st_h',$name);
  67. $name = str_replace('STRINGS','st',$name);
  68. $name = str_replace('NUMBERS','nu',$name);
  69. $name = str_replace('METHODS','me',$name);
  70. $name = str_replace('SYMBOLS','sy',$name);
  71. $name = str_replace('REGEXPS','re',$name);
  72. $name = str_replace('SCRIPT','sc',$name);
  73. return $name;
  74. }