b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/code_highlight_plugin/highlighters/css.highlighter.php - 161 lines - 4528 bytes - Summary - Text - Print

Description: This file is part of the AstonishMe Code plugin. This file is part of the b2evolution project - {@link http://b2evolution.net/}

   1  <?php
   2  /**
   3   * This file is part of the AstonishMe Code plugin.
   4   *
   5   * This file is part of the b2evolution project - {@link http://b2evolution.net/}
   6   *
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   * Parts of this file are copyright (c)2005-2009 by Yabba/Scott - {@link http://astonishme.co.uk/contact/}.
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * {@internal Open Source relicensing agreement:
  20   * Yabba/Scott grant Francois PLANQUE the right to license
  21   * Yabba's/Scott's contributions to this file and the b2evolution project
  22   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  23   * }}
  24   *
  25   * @package plugins
  26   *
  27   * {@internal Below is a list of authors who have contributed to design/coding of this file:
  28   * @author Yabba: Paul Jones - {@link http://astonishme.co.uk/}
  29   * @author Stk: Scott Kimler - {@link http://astonishme.co.uk/}
  30   * }}
  31   *
  32   */
  33  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  34  
  35  /**
  36   * @package AmCode plugin
  37   */
  38  
  39  class am_css_highlighter
  40  {
  41      /**
  42       * Text name of language for display
  43       *
  44       * This is unused whilst "Experimental" as it requires a modification of the plugin
  45       * it would be used to replace the text output above the codeblock instead of ucfirst( language )
  46       *
  47       */
  48      var $language_title = 'CSS';
  49  
  50  
  51      /**
  52       * Boolean are we in strict mode ?
  53       *
  54       */
  55      var $strict_mode = false;
  56  
  57  
  58      /**
  59       * Called automatically on class innit
  60       *
  61       * @param object $parent
  62       * @return object am_css_highlighter
  63       */
  64  	function am_css_highlighter( & $parent )
  65      {
  66          $this->parent = & $parent;
  67          return $this;
  68      }
  69  
  70  
  71      /**
  72       * Highlights code ready for displaying
  73       *
  74       * @param string $block - the code
  75       * @return string highlighted code
  76       */
  77  	function highlight_code( $block )
  78      {
  79  
  80          $block = preg_replace(
  81                      array(
  82                          '~(/\*(.+?)\*/)~s', // highlight comments
  83                          '~(@import([^;]+?);)~i', // highlight includes
  84                      ),
  85                      array(
  86                          '<span class="amc_comment">$1</span>',
  87                          '<span class="amc_keyword">$1</span>'
  88                      ),
  89                           $block );
  90          // highlight remaining css
  91          $block = callback_on_non_matching_blocks(  $block, '~<span([\s\S]+?)</span>~', array( $this, 'highlight_css' ) );
  92  
  93          return $this->parent->tidy_code_output( '<span class="amc_default">'.$block.'</span>' );
  94      }
  95  
  96  
  97      /**
  98       * Highlights css
  99       *
 100       * @param string $block : 2 - the code
 101       * @return string highlighted css
 102       */
 103  	function highlight_css( $block )
 104      {
 105          // highlight all tag/class names and id's
 106          $block = callback_on_non_matching_blocks( $block, '#\{.+?}#s', array( $this, 'highlight_names' ) );
 107          $block = callback_on_non_matching_blocks(  $block, '~<span([\s\S]+?)</span>~', array( $this, 'highlight_rest' ) );
 108          return '<span class="amc_default">'.$block.'</span>';
 109      }
 110  
 111  	function highlight_rest( $block )
 112      {
 113          // highlight all css declarations and values
 114          $block = preg_replace_callback(
 115                          array(
 116                              '#(\{.+?)(})#s',
 117                              '#(\{.+?)$#s',
 118                              '#^([^\{]+?)$#s',
 119                          ), array( $this, 'highlight_declarations' ), $block );
 120          return $block;
 121      }
 122  
 123  
 124      /**
 125       * Highlights css class, id & tag names
 126       *
 127       * @param string $block : 2 - the code
 128       * @return string highlighted names
 129       */
 130  	function highlight_names( $block )
 131      {
 132          $block = preg_replace( array(
 133                          '#\.([\w:]+)#', // highlight classes
 134                          '~#([\w:]+)~', // highlight ID's
 135                      ),
 136                      array(
 137                          '<span class="amc_class">.$1</span>',
 138                          '<span class="amc_id">#$1</span>',
 139                      ),
 140                          $block );
 141          return '<span class="amc_tags">'.$block.'</span>'; // highlight tag names
 142      }
 143  
 144  
 145      /**
 146       * Highlights css declarations and values
 147       *
 148       * @param string $block : 2 - the code
 149       * @return string highlighted css
 150       */
 151  	function highlight_declarations( $block )
 152      {
 153          $block[1] = preg_replace( '#([^:;]+?):([^;]+?(;|$))#',
 154                      '<span class="amc_attribute">$1</span>:<span class="amc_string">$2</span>',
 155                      $block[1] );
 156          return '<span class="amc_default">'.$block[1].'</span>'.( empty( $block[2] ) ? '' : $block[2] );
 157      }
 158  
 159  }
 160  
 161  ?>

title

Description

title

Description

title

Description

title

title

Body